关于api的参考:
![](https://i-blog.csdnimg.cn/blog_migrate/ff48b53879b4055117944c5a8582012a.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/dc9f6911865e053d8820e4c37efd3000.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/158fcfcad515029c142889763e8560cd.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/72d23d84e595f9458fb696216f8691d7.jpeg)
空间在下面的命名空间内;
![](https://i-blog.csdnimg.cn/blog_migrate/0643e5f4eba04519bd6159e9224cfef2.jpeg)
项目构成:
![](https://i-blog.csdnimg.cn/blog_migrate/d26fef2e48cf7d2249c827a4b4514ac5.jpeg)
程序导航:
![](https://i-blog.csdnimg.cn/blog_migrate/5c088bdc63442380f6d35ecffb3b7f53.jpeg)
frame的栈结构:
![](https://i-blog.csdnimg.cn/blog_migrate/f3ea3cfa5379f48a9868d92b11942566.jpeg)
属性和方法:
![](https://i-blog.csdnimg.cn/blog_migrate/3ea4dd83009865992bd06add7ac7d831.jpeg)
项目运行:
![](https://i-blog.csdnimg.cn/blog_migrate/af65b5252b59f6ee4eeb939954734e52.jpeg)
即时窗口中:
![](https://i-blog.csdnimg.cn/blog_migrate/bc6aff14116d08863c082057eb7a50f0.jpeg)
页面跳转:
this.frame.navigate(typeof(页面名));
判断能否后退和前进:
if(this.frame.cangoback)
if(this.frame.cangoforward)
页面返回:
this.frame.goback();
页面前进:
this.frame.goforward();
控件篇:
关于style:
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Margin" Value="5" />
<EventSetter Event="Loaded"Handler="Button_Loaded"/>
</Style>
</Grid.Resources>
1. Style的有效范围
1.1 如果在Application.Resources中声明Style,则它的有效范围是整个程序
![](https://i-blog.csdnimg.cn/blog_migrate/e2ccd0a81511e0b4b98d17be224113c5.gif)
![复制代码](https://i-blog.csdnimg.cn/blog_migrate/3480c06b775daf25621926fdddc32b06.gif)
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Style.xaml" />
<ResourceDictionary Source="Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
![复制代码](https://i-blog.csdnimg.cn/blog_migrate/3480c06b775daf25621926fdddc32b06.gif)
1.2 如果在Window.Resources中声明Style,则它的有效范围是当前窗体
![](https://i-blog.csdnimg.cn/blog_migrate/e2ccd0a81511e0b4b98d17be224113c5.gif)
![复制代码](https://i-blog.csdnimg.cn/blog_migrate/3480c06b775daf25621926fdddc32b06.gif)
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Width" Value="75"></Setter>
<Setter Property="Height" Value="85"></Setter>
<EventSetter Event="Click" Handler="Button_Click"></EventSetter>
</Style>
</Window.Resources>
![复制代码](https://i-blog.csdnimg.cn/blog_migrate/3480c06b775daf25621926fdddc32b06.gif)
1.3 如果在其他控件(例如Grid)的Resources中声明Style,则它的有效范围就是这个控件
![](https://i-blog.csdnimg.cn/blog_migrate/e2ccd0a81511e0b4b98d17be224113c5.gif)
![复制代码](https://i-blog.csdnimg.cn/blog_migrate/3480c06b775daf25621926fdddc32b06.gif)
<Grid.Resources>
<Style TargetType="Button">
<Setter Property="Width" Value="75"></Setter>
<Setter Property="Height" Value="85"></Setter>
<EventSetter Event="Click" Handler="Button_Click"></EventSetter>
</Style>
</Grid.Resources>
![复制代码](https://i-blog.csdnimg.cn/blog_migrate/3480c06b775daf25621926fdddc32b06.gif)
注:
Style中如果只写了TargetType="Button",没有写x:Key,则Style有效范围内的Button的Style默认都是这个Style。
Style中如果写x:Key=“buttonStyle1”了,则引用此Style的方法为Style="{StaticResource buttonStyle1}"
3. TargetType
如果没有给Style指定TargetType,则在写Style时,必须给每个属性添加类型,这样不同的类型可以共用同一个Style:
![](https://i-blog.csdnimg.cn/blog_migrate/e2ccd0a81511e0b4b98d17be224113c5.gif)
<Style x:Key="Style1">
<Setter Property="Button.Width" Value="80"></Setter>
<Setter Property="Button.Height" Value="80"></Setter>
<Setter Property="TextBlock.Text" Value="HelloWorld"></Setter>
</Style>
注:将Style1同时指定给Button和TextBlock,Button会自动忽略不适用它们的属性Text。而二者公有的属性Height,Width,对二者都有效。
查看:
添加超链接;
textbox:
属性:
fontfamily 字体设置;
inputscope:键盘类型 枚举
acceptsreturn :是否支持enter换行 bool
header控件头: 文本说明
textwarping=warp 文本多行
![](https://i-blog.csdnimg.cn/blog_migrate/5e902fd76763ec7e386e8a278e91cefb.jpeg)
关于fontweight bold 为加粗 light 为加亮 black为加黑
关于换行标签(相当于br标签):
<linebreak /> //注:该标签必须有Run标签辅助 for example:<run><run /><linebreak /> <run><run />
关于run子标签
![](https://i-blog.csdnimg.cn/blog_migrate/e0f487d4d7fdc79d14cf67b2ffe4dc67.jpeg)
button按钮:
clickmode属性:
1,设置悬浮(hover)执行点击操作;
2,press, 压下执行
3,release 弹起执行
在c#中:
Button btn = new Button();//用新的Button覆盖之前的button
gd_main.Children.Add(btn);
Grid.SetRow(btn, i);
Grid.SetColumn(btn, j);
btn.Content = num.ToString();
btn.FontSize = 40;
btn.Background = new SolidColorBrush(Blue);
comobox下拉控件:
//不仅仅可以添加文本,其它控件亦可
在c#中添加:
![](https://i-blog.csdnimg.cn/blog_migrate/062c21503bad3664784906d9618914ae.jpeg)
关于在c#中添加控件:
出现位置及大小设置:
![](https://i-blog.csdnimg.cn/blog_migrate/f60c33b870844cd7e5d128af6e65e50a.jpeg)
对齐设置:
![](https://i-blog.csdnimg.cn/blog_migrate/eed634ecbb3d038d3a99a583b326d0d7.jpeg)
窗体中添加控件:
![](https://i-blog.csdnimg.cn/blog_migrate/af9d93469b7b02ef0982a426b86f5832.jpeg)
容器中添加控件:
各控件有所不同:
comobox下拉控件:
//不仅仅可以添加文本,其它控件亦可
在c#中添加:
![](https://i-blog.csdnimg.cn/blog_migrate/7643830299c21c03f04a550398612ef5.jpeg)
布局控件中添加:
![](https://i-blog.csdnimg.cn/blog_migrate/4cbcf4f1da37cecc0600457000ff69a1.jpeg)
border边框控件:
属性:
![](https://i-blog.csdnimg.cn/blog_migrate/d30d81c5986d43a042f4198835e611c0.jpeg)
borderbrush 为边框颜色画刷
borderthickness 为边框宽度
listview控件:
添加项目:
listView1.Items.Add(textBox1.Text);
删除项目:
listView1.Items.Remove(listView1.SelectedItems[listView1.SelectedItems[0].Index]);
关于数据绑定:
c#中的绑定语法:
lv_appear.ItemsSource = list;
xaml中的形式:
![](https://i-blog.csdnimg.cn/blog_migrate/f4f5cf256bd50ba7c695b905e43fe950.jpeg)
显示值的设置:
xaml中
![](https://i-blog.csdnimg.cn/blog_migrate/69d442a3f5e5b31d9e28f36cb6af5018.jpeg)
关于选中项目的内容获取:
![](https://i-blog.csdnimg.cn/blog_migrate/bc21737ab404bd2e3807aa99e203d80f.jpeg)
selecteditem指选取的对象。
selecteditem指选取的值。xaml需要设置
![](https://i-blog.csdnimg.cn/blog_migrate/08aed258236c36c8f6835ca8d259ef67.jpeg)
grid:
Grid.Columdefinitons
来声明一列。
Height表示该行的高度,
width表示列的宽度。
其中”*”表示该行的高度和宽度基于可用空间(去掉其它固定高度行的高度)的加权比例.
stackpanel:
messagedialog:
slider滑动控件:
flyout浮出控件:
stackpanel:
属性:
orientation: 排列方式 水平horizontal,垂直?
messagedialog:
即wpf的messagebox控件
括号内的属性:
(string1,string2)
//string1 表示显示的内容,string2表示显示的标题。
![](https://i-blog.csdnimg.cn/blog_migrate/f77c020c31eedfcb4717d76e5e0781d4.jpeg)
弹出提示框:
![](https://i-blog.csdnimg.cn/blog_migrate/bb81a425932c1211e3407bea17d6f96d.jpeg)
注:其中的await showAsync()为异步操作(?);
需要命名空间:using Windows.UI.Popups;
slider滑动控件:
![](https://i-blog.csdnimg.cn/blog_migrate/77c2cbe3563b02d297ce45514a9ae26f.jpeg)
flyout浮出控件:
flyout为button的默认click事件。
如果用于其他控件,则代码如下:
xaml:
<TextBox Header="请输入:" Name="txt_enter" Grid.Column="1" Grid.Row="1" Height="59" RenderTransformOrigin="0.513,4.86" Margin="10,148,45,0" TextChanged="txt_enter_TextChanged" >
<FlyoutBase.AttachedFlyout>
<Flyout>
<DatePicker/>
</Flyout>
</FlyoutBase.AttachedFlyout>
c#:
private void txt_enter_TextChanged(object sender, TextChangedEventArgs e)
{
FrameworkElement ele = sender as FrameworkElement;
if (txt_enter.Text == "我是鲁新")
FlyoutBase.ShowAttachedFlyout(ele);
}
4.15 浮出控件(Flyout)
浮出控件(Flyout)是一个轻型的辅助型的弹出控件,通常会作为提示或者要求用户进行相关的交互来使用。Flyout控件与
Windows Phone
里面的弹出框MessageDialog是有很大区别的,首先Flyout控件是一个辅助控件,需要与其他控件结合起来才能使用,还有就是取消的规则不一样,Flyout控件可以通过单击或在外部点击都可以轻松消除浮出控件。你可以使用Flyout控件收集用户输入、显示与某个项目相关的更多信息或者要求用户确认某个操作。只有当为了响应用户点击时才应显示Flyout控件,也就是说Flyout控件并不是直接就显示出来,而是必须要用户的操作才能呈现出来;当用户在弹出窗口外部点击时,Flyout控件就会消失,这也是Flyout控件默认的关闭规则。控件的XAML语法如下:
< Button
![](https://i-blog.csdnimg.cn/blog_migrate/cf85a8d4ca88fb2ab5a8d631a0459d17.gif)
< Button