wpf - 获取或设置附加属性的访问器在数据绑定(bind)时未触发? WPF

标签 wpf data-binding properties attached-properties

我有一个自定义附加属性,但从未在数据绑定(bind)上访问访问器。 这些访问器是否意味着每次附加属性更改时都会被访问?

  public static readonly DependencyProperty CharacterColumnNumberProperty =
        DependencyProperty.RegisterAttached("CharacterColumnNumber", typeof(int), typeof(DragCanvas), new UIPropertyMetadata(1));

    public static int GetCharacterColumnNumber(UIElement uiElement)
    {
        if (uiElement != null)
            return (int)uiElement.GetValue(CharacterColumnNumberProperty);
        else return 0;
    }

    public static void SetCharacterColumnNumber(UIElement uiElement, int value)
    {
        if (uiElement != null)
        {
            uiElement.SetValue(CharacterColumnNumberProperty, value);
            DragCanvas.SetLeft(uiElement, value * 10);
        }
    }

XAML:

 <Setter Property="local:DragCanvas.CharacterColumnNumber" Value="{Binding Path=CharacterColumnNumber, Mode=TwoWay}" />

最佳答案

不,他们不是。如果您想知道内部属性引擎何时更改这些值,您可以传入 PropertyChangedCallback 的委托(delegate)。 UIPropertyMetadata 的参数。

每次属性更改时都会调用此委托(delegate),无论是通过 CLR 属性还是通过依赖属性引擎内部的更改(即绑定(bind))。

关于wpf - 获取或设置附加属性的访问器在数据绑定(bind)时未触发? WPF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1573595/

相关文章:

c# - 您可以通过 Property setter 实例化对象吗?

java - Maven 插件没有在我想要的地方运行

.net - 当图像源有效(不为空)时触发隐藏文本

wpf - 如何为 bool[] 中的值实现 INotifyPropertyChanged 功能?

c# - 在 C# 中创建音乐库和播放列表

android - 如何将模型/POJO 与 android 数据绑定(bind)、房间和改造一起使用?

wpf - 如何将 Viewport3D 导出​​为 2d 图像文件?

c# - 强制 DataGrid 列验证 (WPF)

asp.net - 将字典绑定(bind)到 GridView

Javascript - 将对象属性转换为函数范围内的变量