有没有办法指定自定义依赖属性的默认绑定模式和更新触发器? [英] Is there a way to specify a custom dependency property's default binding mode and update trigger?

查看:319
本文介绍了有没有办法指定自定义依赖属性的默认绑定模式和更新触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让这样做,默认情况下,当我绑定到我的一个依赖属性时,绑定模式是双向的,update-trigger属性被更改。有没有办法这样做?



这是一个依赖属性之一的例子:

  public static readonly DependencyProperty BindableSelectionLengthProperty = 
DependencyProperty.Register(
BindableSelectionLength,
typeof(int),
typeof(ModdedTextBox),
new PropertyMetadata(OnBindableSelectionLengthChanged));


解决方案

注册属性时,使用以下命令初始化元数据: / p>

 新的FrameworkPropertyMetadata 
{
BindsTwoWayByDefault = true,
DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
}


I would like to make it so that, as default, when I bind to one of my dependency properties the binding mode is two-way and update-trigger is property changed. Is there a way to do this?

Here is an example of one of my dependency properties:

public static readonly DependencyProperty BindableSelectionLengthProperty =
        DependencyProperty.Register(
        "BindableSelectionLength",
        typeof(int),
        typeof(ModdedTextBox),
        new PropertyMetadata(OnBindableSelectionLengthChanged));

解决方案

When registering the property, initialize your metadata with:

new FrameworkPropertyMetadata
{
    BindsTwoWayByDefault = true,
    DefaultUpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
}

这篇关于有没有办法指定自定义依赖属性的默认绑定模式和更新触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆