WPF 数据绑定需要注意的地方
2014-02-17 18:08
267 查看
在学习WPF过程中发现的一些需要注意的地方,在此记录,以备后查。
14.2.17
FrameworkElement,控件的常用方法:
1. public void SetValue(DependencyProperty dp, object value);设置XAML文件中WindowsSource中的一个资源,object value为Key的名称而非Name.
2. public void SetResourceReference(DependencyProperty dp, object name);设置某个属性值
3. 设置属性的方式与绑定效果相同:
textblockNo.Content = source;
Binding bind = new Binding("Key");
control.SetBinding(TextBlock.TextProperty,binding);
----------------------------------------------------------------------------
Binding bind = new Binding("Key");
binding.Source = source;
control.SetBinding(TextBlock.TextProperty,binding);
有人知道原因吗?.
4. 一个简单转换器的写法:
public class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value.ToString().IndexOf("+") >= 0
|| value.ToString().IndexOf("[") >= 0)
return value;
else return "+" + value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
5. 简单样式的写法,写在<Window.Resources/>中
<Style x:Key="S_TextBlock_No" TargetType="TextBlock">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="FontFamily" Value="微软雅黑"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Margin" Value="0,5,0,0"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
6. XAML中绑定Window.Recources的方法
<TextBlock x:Name="tb_sampleCode1_2" Style="{DynamicResource S_TextBlock_Content}"/>:
后台等同于
tb_sampleCode1_2.SetResourceReference(TextBlock.StyleProperty, "S_TextBlock_Content");
7. Block中只能加一个下级,因此可以通过增加一个容器来扩展.
14.2.17
FrameworkElement,控件的常用方法:
1. public void SetValue(DependencyProperty dp, object value);设置XAML文件中WindowsSource中的一个资源,object value为Key的名称而非Name.
2. public void SetResourceReference(DependencyProperty dp, object name);设置某个属性值
3. 设置属性的方式与绑定效果相同:
textblockNo.Content = source;
Binding bind = new Binding("Key");
control.SetBinding(TextBlock.TextProperty,binding);
----------------------------------------------------------------------------
Binding bind = new Binding("Key");
binding.Source = source;
control.SetBinding(TextBlock.TextProperty,binding);
有人知道原因吗?.
4. 一个简单转换器的写法:
public class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value.ToString().IndexOf("+") >= 0
|| value.ToString().IndexOf("[") >= 0)
return value;
else return "+" + value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
5. 简单样式的写法,写在<Window.Resources/>中
<Style x:Key="S_TextBlock_No" TargetType="TextBlock">
<Setter Property="Foreground" Value="Blue"/>
<Setter Property="FontFamily" Value="微软雅黑"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="Margin" Value="0,5,0,0"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
6. XAML中绑定Window.Recources的方法
<TextBlock x:Name="tb_sampleCode1_2" Style="{DynamicResource S_TextBlock_Content}"/>:
后台等同于
tb_sampleCode1_2.SetResourceReference(TextBlock.StyleProperty, "S_TextBlock_Content");
7. Block中只能加一个下级,因此可以通过增加一个容器来扩展.
相关文章推荐
- WPF 个人经验总结:需要注意的地方
- 采用Json字符串,往服务器回传大量富文本数据时,需要注意的地方,最近开发时遇到的问题。
- android 获取数据-需要注意的地方(系统优化)
- ASP.NET数据控件绑定需要注意的问题
- WPF为控件扩展的附加属性不起作用需要注意的地方
- wpf application线程需要注意的地方
- 千万级数据的查询需要注意的地方
- Mybatis 实现插入数据时需要注意的地方
- DataList等控件嵌套绑定的一个需要注意的地方
- 数据绑定需要注意的一些
- WSDL接口数据传递以及外网发布需要注意的地方
- Pear 的Excel类写数据需要注意的地方
- 本文从如何建立mysql索引以及介绍mysql的索引类型,再讲mysql索引的利与弊,以及建立索引时需要注意的地方 首先:先假设有一张表,表的数据有10W条数据,其中有一条数据是nickname='
- java里String需要注意的地方以及基本数据类型注意点(不定期修改更新)
- WPF应用加载图片URI指定需要注意的地方
- Java 数据类型中需要注意的几个小地方
- python 类属性 、实例属性,可变数据结构作为类属性需要注意的地方
- Java 得到指定数据Excel2003 与2007需要注意的地方
- springmvc接收复杂类型的json数据需要注意的地方
- JSON格式-给后台传递数据时需要注意的地方