WP8.1 Study4:WP8.1中控件集合应用
1、AutoSuggestBox的应用
在xaml里代码可如下:
<AutoSuggestBox Name="autobox"
Header="suggestions" GotFocus="autobox_GotFocus"
TextChanged="autobox_TextChanged">
<AutoSuggestBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>
在C#代码添加类似代码,注意要用 Gotfocus事件和TextChaged事件(用来筛选)
ObservableCollection<string> items = new ObservableCollection<string>() { "w1", "w2", "w3", "msmdms","我的","你要" };
private void autobox_GotFocus(object sender, RoutedEventArgs e)
{
autobox.ItemsSource=items;//数据源items
}
private void autobox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
string change = sender.Text;
autobox.ItemsSource = items.Where(s =>s.Contains(change));//筛选s, 如同数据库操作
}
2、MessageDialog, ContentDialog的应用
(1)WP8.1中的messagebox变成了MessageDiaglog,用法是用C#代码调用,简单的调用程序如下:
private async void messageDialogButton_Click(object sender, RoutedEventArgs e)
{
MessageDialog messageDialog = new MessageDialog("MessageBox --> MessageDialog", "MessageDialog");
await messageDialog.ShowAsync();
}
(2)ContentDialog 则可以设置为部分或者全屏,或者直接在项目里新建一个 ContentDialog,其C#代码如下:
private async void Button_Click_2(object sender, RoutedEventArgs e)
{ ContentDialog dialog=new ContentDialog(){
Title="这是一个项目",
Content="密匙",
PrimaryButtonText="um1",
SecondaryButtonText="um2"
};
dialog.FullSizeDesired = true;//设置全屏
ContentDialogResult result=await dialog.ShowAsync();
if (result == ContentDialogResult.Primary)
{
show.Content = "nonshow";
}
else if (result==ContentDialogResult.Secondary)
{
show.Content = "showagain";
}
}
3、Flyout应用
下面用Button 嵌入一个flyout,下面xaml代码如下:
<Button Name="show" Content="show">
<Button.Flyout>
<Flyout>
<StackPanel>
<TextBlock Text="我的项目"/>
<Button Content="你好" Click="Button_Click_2"/>
</StackPanel>
</Flyout>
</Button.Flyout>
</Button>
还可以内嵌menuflyout,xaml代码如下:
<Button Name="show" Content="show">
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="123"/>
<MenuFlyoutItem Text="456" Click="showBt_Click"/>
</MenuFlyout>
</Button.Flyout>
</Button>
还可以用ListPickerFlyout 内嵌
<Button Name="show" Content="show">
<Button.Flyout>
<ListPickerFlyout ItemsSource="{Binding items}">
<ListPickerFlyout.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ListPickerFlyout.ItemTemplate>
</ListPickerFlyout>
</Button.Flyout>
</Button>
4、BottumAppBar
就是ApplicationBar ,xaml代码如下:
<Page.BottomAppBar>
<CommandBar>
<CommandBar.PrimaryCommands>
<AppBarButton Icon="Accept" Label="Accept"/>
<AppBarButton Icon="Cancel" Label="Cancel"/>
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Icon="Help" Label="Help"/>
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.BottomAppBar>
5、StatusBar
可以在设计页面隐藏起来,也可以用C#来设计它。
private async void statusBt_Click(object sender, RoutedEventArgs e)
{ Windows.UI.ViewManagement.StatusBar statusbar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
await statusbar.HideAsync();//隐藏 }
使用它的progress inditator, C#代码如下:
private async void statusBt_Click(object sender, RoutedEventArgs e)
{ Windows.UI.ViewManagement.StatusBar statusbar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
// await statusbar.HideAsync();
statusbar.BackgroundColor = Colors.White;
statusbar.ForegroundColor = Colors.Blue;
var progress = statusbar.ProgressIndicator;//获取状态栏的指示器
progress.Text = "连接中";
await progress.ShowAsync(); }
6、ListBox及Listview
ListView继承于ListBox,详细的可以查阅相关文档。下面用例子介绍ListView。
在Page.xaml代码中
<ListView Name="view1" ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.IsScrollInertiaEnabled="True"
Height=""
SelectionChanged="view1_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate> <StackPanel Orientation="Horizontal">
<TextBlock Style="{ThemeResource ListViewItemContentTextBlockStyle}" Text="{Binding Path=Id}" Width="" TextAlignment="Left"/>
<TextBlock Style="{ThemeResource ListViewItemContentTextBlockStyle}" Text="{Binding Path=Name}" Width="" TextAlignment="Left"/>
</StackPanel> </DataTemplate>
</ListView.ItemTemplate>
</ListView>
在Page.xaml.cs中SelectionChanged()事件和Datading 部分代码如下:
private async void view1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string str = "";
foreach (var item in e.AddedItems)
{
str = (item as School).Id + (item as School).Name;
}
MessageDialog diolog = new MessageDialog(str);
await diolog.ShowAsync();
}
...
ObservableCollection<School> school = new ObservableCollection<School>()
{
new School{Id=,Name="华农"},
new School{Id=,Name="华工"},
new School{Id=,Name="华农"},
};
view1.ItemsSource = school; public class School
{
private string name;
private int id; public string Name
{
get { return name; }
set { name = value; }
}
public int Id
{
get { return id; }
set { id = value; }
}
}
7. Magic Number:10
在 8.0 时代,Magic Number 为 12,也就是间距最好都设为 12 的倍数,或者 6。
但到了 8.1,微软将 12 改成了 10。
以上内容大部分是参考http://www.cnblogs.com/xiaoshi3003/p/3739510.html 的。
----------------------------------------------------------------------------------------------------------------------------
总结
1、容器Panel Controls:
Canvas, StackPanel, Grid…
2、文本控件Text Handling Controls:
TextBlock、RichTextBlock、TextBox、PasswordBox、AutoSuggestBox...
3、按钮Buttun控件:
ToggleButton、CheckBox、RadioButton、AppBarButton、AppBarToggleButton...
4、进度显示控件:
ProgressRing、ProgressBar
5、一些好用的控件:
DatePicker / TimePicker、Flyout(包括MenuFlyout、List Picker Flyouts、Date/TimePicker Flyouts、Generic Picker Flyouts)、ContentDialog
6、系统的UI:
CommandBar、StatusBar、Soft Buttons(一些没有用)
注:RequestedTheme是可以设置空间及页面的主题的属性。
WP8.1 Study4:WP8.1中控件集合应用的更多相关文章
- 控件包含代码块(即 <% ... %>),因此无法修改控件集合
错误: “/”应用程序中的服务器错误. 控件包含代码块(即 <% ... %>),因此无法修改控件集合. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解 ...
- C#中控件数组的讨论
VB用得习惯后,到C#中来觉得很奇怪,如此好的控件数组怎么不见了.“众所周知,控件数组最主要的两个优点:可以循环附值:可以响应同一个事件.从而大大简化了代码.引自http://wenku.baidu. ...
- WPF 中获取DataGrid 模板列中控件的对像
WPF 中获取DataGrid 模板列中控件的对像 #region 当前选定行的TextBox获得焦点 /// <summary> /// 当前选定行的TextBox获得焦点 /// &l ...
- Metro中控件WebView访问外部的网页显示一片空白
Metro中控件WebView访问外部的网页显示一片空白 解决方案: 下载安装了Initex.Software.Proxifier.v3.21.Standard.Edition.Incl.Keyma ...
- form表单中控件较多,加载完成后切换页面都很慢的解决方法
form表单中控件较多,加载完成后点击都很慢,为什么?我一页面中form表单里面上百个控件(如input.select.radio.checkbox等),还有一些js脚本,加载速度还可以,都能全部显示 ...
- selenium遍历控件集合
场景:需要重复增加地址栏信息,如果地址信息超过了5个就不开始增加 如图: 1.找到控件集合,在遍历每个子元素,在进行选择 1.先找到最外层的div的控件集合 2.外层的css定位为: int star ...
- C#中控件的CheckState和Checked属性区别?
Checked 和CheckState都是检查控件选中状态,都能判断是否选中控件. 只是Checked 通过布尔判断(true & false): CheckState 通过枚举判断. che ...
- duilib中控件拖拽功能的实现方法(附源码)
转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/41144283 duilib库中原本没有显示的对控件增加拖拽的功能,而实际 ...
- MFC中控件的TAB顺序 ----转载
在MFC中添加控件后,按Ctrl+d可以改变控件TAB顺序,怕自己忘了,一个神奇的东西,记下. 关于改变Tab顺序的方法有以下几种: 方法一:在动态创建控件的时候STYLE设置成为WS_CHILD|W ...
随机推荐
- 详解zabbix安装部署(Server端篇)
原文:http://blog.chinaunix.net/uid-25266990-id-3380929.html Linux下常用的系统监控软件有Nagios.Cacti.Zabbix.Monit等 ...
- JAVA调用C语言写的SO文件
JAVA调用C语言写的SO文件 因为工作需要写一份SO文件,作为手机硬件IC读卡和APK交互的桥梁,也就是中间件,看了网上有说到JNI接口技术实现,这里转载了一个实例 // 用JNI实现 // 实例: ...
- php输出csv文件 简单实现
<?php $list = array ( "George,John,Thomas,USA", "James,Adrew,Martin,USA", ); ...
- Python策略模式实现源码分享
1.让一个对象的某个方法可以随时改变,而不用更改对象的代码 2.对于动态类型的Python语言,不需要定义接口 3.基本的实现方法:用类作为参数传递 例如: 12_eg3.py class Movea ...
- SQL Server Native Client 安装方法
在 server 2008 r2 里面搜索到: sqlncli.msi 安装即可
- 【转】APP的缓存文件到底应该存在哪?看完这篇文章你应该就自己清楚了
只要是需要进行联网获取数据的APP,那么不管是版本更新,还是图片缓存,都会在本地产生缓存文件.那么,这些缓存文件到底放在什地方合适呢?系统有没有给我们提供建议的缓存位置呢?不同的缓存位置有什么不同呢? ...
- DIY_hlstudio_WIN7PE【69M】网络版【89M】
DIY_hlstudio_WIN7PE[69M]网络版[89M] hlstudio的骨头版PE非常精简,由于启动方式和用法不同,个人进行了如下修改:1.原来的合盘修改为bootmgr直接起动ISO镜像 ...
- VS2012更改项目编译后文件输出目录
1.现在我的解决方案里有存在两个项目,分别是类库项目ClassLibrary1和控制台项目ConsoleApplication1,默认情况下当解决方案重新生成后,这两个项目所对应的编译后文件分别会存在 ...
- nodeschool.io 3
~~ MY FIRST I/O! ~~ Write a program that uses a single synchronous filesystem operation toread a fil ...
- Spring Boot 环境变量读取 和 属性对象的绑定
网上看到的一些方法,结合我看到的 和我们现在使用的.整理成此文: 第一种方法 参见catoop的博客之 Spring Boot 环境变量读取 和 属性对象的绑定(尊重原创) 第二种方法 class不用 ...