SL - 整理 - Behavior
来源:互联网 发布:百度云 for mac 编辑:程序博客网 时间:2024/04/30 23:13
behavior是trigger的高级用法,能更加灵活的处理事件,主要是能灵活的获得页面中的元素。它需要一个起点来使this.AssociatedObject有值
xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:MyInteractivity="clr-namespace:xxxxxxxxxx.xxxxxxxx.Interactivities"
<Interactivity:Interaction.Behaviors>
<MyInteractivity:LookupIssuerBehavior> <Interactivity:Interaction.Triggers> <Interactivity:EventTrigger SourceName="LayoutRoot" EventName="GotFocus"> <Interactivity:InvokeCommandAction CommandName="GotFocusCommand" /> </Interactivity:EventTrigger> </Interactivity:Interaction.Triggers> </MyInteractivity:LookupIssuerBehavior> </Interactivity:Interaction.Behaviors>using System.Windows.Interactivity;
///
<summary> /// LookupIssuer Behavior /// </summary> public class LookupIssuerBehavior : Behavior<UserControl>{
public LookupIssuerBehavior(){
}
void AssociatedObjectKeyDown(object sender, KeyEventArgs e){
if (e.Key == Key.Enter){
var viewModel = this.AssociatedObject.DataContext as DataModels.IssuerViewModels.LookupIssuerViewModel;viewModel.Search();
}
}
void tbxBusinessDomainOwnerKeyUpProcess(object sender, KeyEventArgs e){
LookupIssuerViewModel viewModel = this.AssociatedObject.DataContext as LookupIssuerViewModel;viewModel.BusinessDomainOwner = (sender
as TextBox).Text;}
protected override void OnAttached(){
base.OnAttached(); this.AssociatedObject.Loaded += new RoutedEventHandler(AssociatedObjectLoaded);}
void AssociatedObjectLoaded(object sender, RoutedEventArgs e){
this.AssociatedObject.KeyDown += new KeyEventHandler(AssociatedObjectKeyDown); TextBox tbxBusinessDomainOwner = this.AssociatedObject.FindName("tbxBusinessDomainOwner") as TextBox;tbxBusinessDomainOwner.KeyUp +=
new KeyEventHandler(tbxBusinessDomainOwnerKeyUpProcess);}
protected override void OnDetaching(){
base.OnDetaching(); this.AssociatedObject.Loaded -= new RoutedEventHandler(AssociatedObjectLoaded);}
}
0 0
- SL - 整理 - Behavior
- SL
- SL
- SL - 整理 - Loading状态的实现
- SL - 整理 - WPF实现MDI窗体
- SL - 整理 - WrapPanel (换行组建)
- behavior
- BEHAVIOR
- Behavior
- Behavior
- SL - 整理 - 给组件绑定资源文件值
- SL - 整理 - 将验证做到资源文件中
- SL - 整理 - 多线程调用UI组件时需注意的
- SL - 整理 - 输入更变事件(使即时输入内容能被更新到vm)
- SL - 整理 - 定义Dependency属性(使自定义组件属性能被绑定)
- sl 基础
- 学习SL
- SL Controller
- 堆和栈的区别
- SL - DataGrid - 使Header能被DataBinding(setter)
- 指来指去
- SL - 输入验证
- C指针原理(37)-gtk
- SL - 整理 - Behavior
- SL - 使用在程序集中的图片
- SL - ToolTip的试用
- VS调试总结
- 判断android app或者service是否存在
- 虚拟机
- Oracle 之 注释的添加和查看
- 图像镜像
- SL - 整理 - 给组件绑定资源文件值