WPF笔记 ( xmlns引用,Resource、Binding 前/后台加载,重新绑定) 2013.6.7更新
来源:互联网 发布:大众网络报 编辑:程序博客网 时间:2024/06/05 15:51
1、xmlns
Mapping URI的格式是clr-namespace:<clr namespace>[;assembly=<assembly name>]
xmlns:converter="clr-namespace:Pansoft.SCV.Workflows.OpenAccount.ValueConverter"
(2)如果自定义类和XAML处在不同的Assembly之中。除了clr-namespace值外,还必须提供assembly的值。
xmlns:converter="clr-namespace:Pansoft.SCV.UIFramework.ValueConverter;assembly=Pansoft.SCV.UIFramework"
clr-namespace和assembly的拼写必须都是小写。
这样在XAML中就可以通过namespace prefix和类名使用自定义的元素了。举例:
<converter:ImageSourceConverter x:Key="ImageConverter"/>
2、Resource
前台:
<Page.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Pansoft.SCV.UIFramework;component/Style/GlobaStyle.xaml"/> </ResourceDictionary.MergedDictionaries> <converter:ImageSourceConverter x:Key="ImageConverter"/> <Style TargetType="{x:Type TextBox}"> </Style> </ResourceDictionary> </Page.Resources>
后台:
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("../Pansoft.SCV.Workflows.OpenAccount;component/Style/GlobaStyle.xaml", UriKind.Relative) });
或者
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/Pansoft.SCV.Workflows.OpenAccount;component/Style/GlobaStyle.xaml") });
3、Binding
前台:
<trans:OpenAccountTranscation x:Key="WorkflowNode"/>
或者
Resources.Add("WorkflowNode", node.Owner.Transcation);
调用:
<Page.DataContext> <Binding Source="{StaticResource WorkflowNode}"/></Page.DataContext>
<TextBlock Text="{Binding Name}" FontSize="18" Margin="20,0"/>
或者直接写:
DataContext = node.Owner.Transcation;
后台:
Binding MyBinding = new Binding(); MyBinding.Path = new PropertyPath("Name"); MyBinding.Mode = BindingMode.OneWay; MyBinding.Source = node.Owner.Transcation; MyTextBlock.DataContext = node.Owner.Transcation; MyTextBlock.SetBinding(TextBlock.TextProperty, MyBinding);
4、后台重新绑定
xaml:
<Button x:Name="BtnSwitchLangs" Content="{DynamicResource Execute}" Width="200" Height="60" Click="Button_Click_2" Margin="0,5"/>
后台(重新绑定):
BtnSwitchLangs.SetResourceReference(ContentProperty, "ReExecute");//为内容绑定新的源
- WPF笔记 ( xmlns引用,Resource、Binding 前/后台加载,重新绑定) 2013.6.7更新
- WPF笔记 ( xmlns引用,Resource、Binding 前/后台加载,重新绑定)
- wpf 后台绑定数据 binding
- XMPP资源绑定(Resource Binding)
- WPF中的属性绑定 binding
- WPF绑定(Binding)讲解大全
- WPF绑定Binding及模式
- c#--wpf数据绑定binding
- WPF笔记--Binding
- WPF笔记--Binding补充
- RDLC报表更新和重新绑定数据源引用
- EDT资源绑定(Resource Binding)简介
- WPF 值绑定binding (上)
- wpf后台代码数据绑定
- WPF 后台设置数据绑定
- WPF 学习笔记 - 7. Resource
- WPF 学习笔记 - 7. Resource
- WPF 学习笔记 - 8. Binding (1)
- cmd 命令行下如何复制,粘贴
- linux stat函数讲解
- 虚析构函数作用,虚构造函数用法(转)
- owasp appsec
- C/C++中判断某一文件或目录是否存在
- WPF笔记 ( xmlns引用,Resource、Binding 前/后台加载,重新绑定) 2013.6.7更新
- PL/SQL中触发器的简单使用
- 不同回文子串数目 hdu 3948
- 多态性和虚函数、纯虚函数
- 用struts2 action type=plaintext直接输出文本信息
- 送给“苦逼”的IT人系列1:IT人的“钱”景以及收入的两道坎
- RPC远程过程调用实例剖析(转载)
- 浅析远程过程调用 RPC
- Ubuntu操作系统安装使用教程