Allow only OneWayToSource binding mode

百般思念 提交于 2019-12-02 02:19:58

It's a „bit” hacky, but you can create a Binding-derived class and use that instead of Binding:

[MarkupExtensionReturnType(typeof(OneWayToSourceBinding))]
public class OneWayToSourceBinding : Binding
{
    public OneWayToSourceBinding()
    {
        Mode = BindingMode.OneWayToSource;
    }

    public OneWayToSourceBinding(string path) : base(path)
    {
        Mode = BindingMode.OneWayToSource;
    }

    public new BindingMode Mode
    {
        get { return BindingMode.OneWayToSource; }
        set
        {
            if (value == BindingMode.OneWayToSource)
            {
                base.Mode = value;
            }
        }
    }
}

In XAML:

<controls:EntitiesUserControl EntitiesCount="{local:OneWayToSourceBinding CountOfEntities}" />

The namespace mapping local might be something else for you.

This OneWayToSourceBinding sets the Mode to OneWayToSource and prevents setting it to anything else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!