WPF: One-way binding on entire DataGrid

走远了吗. 提交于 2021-02-11 05:08:41

问题


Is there a way to mark the entire DataGrid as one-way binding?


回答1:


You can create a new class such as OneWayExtension that inherits binding.

 public class OneWayExtension : Binding
{
    public OneWayExtension()
        : base()
    {
        Initialize();
    }

    public OneWayExtension(string path)
        : base(path)
    {
        Initialize();
    }

    private void Initialize()
    {
        this.Source = YourSourceOrMakeThisAParameter;
        this.Mode = BindingMode.OneWay;
    }
}

You can then call this by

{local:OneWay PathOfData}



回答2:


I know this is already answered, but can't you just set the binding Mode on the DataGrid's ItemsSource property to OneWay?



来源:https://stackoverflow.com/questions/2365865/wpf-one-way-binding-on-entire-datagrid

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