Windows开发笔记5{MVVM模式}
17.实例:数据绑定与通知
对App.xaml中xaml代码解释:
<Application
x:Class="数据绑定与通知.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:数据绑定与通知"
RequestedTheme="Light">
</Application>
类比一下
Class Person
{}
Class Student :Person
{}
Student stu=new Student(); 这句等价于:
<Person
x:Class="命名空间.Student"
x:Name="stu"
…. >
18.使用静态资源
<Application
x:Class="数据绑定与通知.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:数据绑定与通知"
RequestedTheme="Light">
<Application.Resource>
//标签中的Resource标签表示的是一个静态的资源对象,如果代码中或标签中使用一个东西,而且这个东西只需创建一次,那么就可以写在这里//
</Application.Resource>
</Application>
19.实现使用静态资源,前台和后台的数据类型转换
功能:如后台用m表示男,f表示女,在前台用汉字表示男女
->添加一个相应的转换类,这个类继承一个接口IValueConverter;
这个接口提供两个方法:
1)Convert:从后台转到前台
2)ConvertBack:从前台转到后台
->在Application.xaml中添加<Application.Resource></Application.Resource>