13.AppBar
//当手势向上或者鼠标右键的时候,会显示AppBar,AppBar分为顶部TopAppBar、底部BottonAppBar两块,建议把主要操作放到底部,顶部有特殊意义再放(比如IE)。
eg:Xaml中Page的TopAppBar、BottonAppBar两个属性赋值AppBar类型(style),然后Content内容自由绘制,一般绘制横向的图型图标,一般采用StandardStyles.xaml中预置的
顶部TopAppBar
<Page.TopAppBar> <AppBar> <AppBar.Content>//<!--这句可以省略不写--> <StackPanel Orientation="Horizontal"> //<!--以下是音乐播放按钮图标--> <Button Style="{StaticResource PlayAppBarButtonStyle}" AutomationProperties.Name="播放"></Button> //<!-- AutomationProperties.Name将默认play按钮改为“播放”--> <Button Style="{StaticResource EditAppBarButtonStyle}" AutomationProperties.Name="编辑"></Button> //<!--style—到common文件夹下的standardStyles中查找,并别忘记把它们从注释中拿出来启用--> </StackPanel> </AppBar.Content> </AppBar> </Page.TopAppBar>
底部BottonAppBar
<Page.BottomAppBar> <AppBar> <StackPanel Orientation="Horizontal"> <TextBlock Text="地址"></TextBlock> <TextBlock Width="500"></TextBlock> <Button>转到</Button> </StackPanel> </AppBar> </Page.BottomAppBar>
PS:总算找到这个按钮了 Style="{StaticResource BackButtonStyle}"
<Button Content="Button" HorizontalAlignment="Left" Height="78" Margin="103,166,0,0" VerticalAlignment="Top" Width="148" Style="{StaticResource BackButtonStyle}"/>
#高级:IsOpen打开状态(可以实现程序打开时默认AppBar显示);IsSticky是否盯住;Opened、Closed打开关闭事件
<Page.BottomAppBar> <AppBar IsOpen="True">
14.其他常用控件
1)ProgressBar
<ProgressBar HorizontalAlignment="Left" Height="41" Margin="93,169,0,0" VerticalAlignment="Top" Width="398" Value="30" IsIndeterminate="True"/> //IsIndeterminate="True"显示一直处于类似缓冲状态,表示正在进行
IsIndeterminate="True"时:
2)ProgressRing
<ProgressRing HorizontalAlignment="Left" Height="83" Margin="93,390,0,0" VerticalAlignment="Top" Width="240" IsActive="True"/> //<!--IsActive="True"需要启动它,才会显示效果-->
3)ToggleSwitch
<ToggleSwitch Header="ToggleSwitch" HorizontalAlignment="Left" Height="75" Margin="85,240,0,0" VerticalAlignment="Top" Width="102"/> <!--开关控件,IsOn是否打开,OffContent/OnContent/Heade/关闭/打开/头部的显示内容;Toggled更改事件-->
4)ScrollViewer
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" Height="189" Margin="322,204,0,0" VerticalAlignment="Top" Width="295"> //<!--ScrollViewer默认只有纵向滚动条,通过设置Horizontal(Vertical)ScrollBarVisibility改变滚动条属性--> <Image Source="image/1b.jpg" Width="800" Height="800"></Image> </ScrollViewer>
15.异步编程
*异步方法不用等任务结束后才返回.异步编程可以避免界面卡死的问题,但是会导致编写"等待一个异步操作执行完成再执行一段代码"的程序很麻烦
*异步方法返回Task或者IAsyncOperation对象(鼠标悬停会显示"可等待"),一般以Async结尾,异步方法不会等结束才返回.
*在.net4.5中引入了async/await关键字,可以在异步方法调用前加入await关键字,这样方法中这一行之后的代码都将在异步方法执行完成后才执行.注意:一个方法中如果有await,则必须标注为async.
*可以直接在await前声明变量,当异步方法执行完成后把执行结果返回设置给变量,一般用var自动推断.
*WinRT中所有执行时间可能会较长操作(一般是IO操作)都被设置为异步方法.
//方法中如果有一个地方用到了await,则方法需要标注为async private async void Button_Click_1(object sender, RoutedEventArgs e) { MessageDialog msgDlg = new MessageDialog("Hello!"); msgDlg.Commands.Add(new UICommand("yes")); msgDlg.Commands.Add(new UICommand("no")); var result = await msgDlg.ShowAsync(); //一般异步方法都是以Async结尾,异步方法都可以使用await编程“好像同步” //异步执行结束后才继续详细执行 //var info = msgDlg.ShowAsync(); //info.Completed = (a1, a2) => //{ // string cmd = a1.GetResults().Label; //}; }
MessageDialog
MessageDialog msgDlg = new MessageDialog("是否删除?"); msgDlg.Commands.Add(new UICommand("是") {Id=1}); msgDlg.Commands.Add(new UICommand("否") { Id = 2}); var result = await msgDlg.ShowAsync(); if ((int)result.Id == 1) { // } else if ((int)result.Id == 2) { }