I'm using three UserControls that have a datagrid. One of the UserControl's DataGrid needs to have a column readonly attribute set to True.

Right I'm doing this after InitializeComponent():

v_uc1.v_datagrid.Columns[1].IsReadOnly = true;

Is there a cleaner way (XAML) to do this?

有帮助吗?

解决方案

You can make just one UserControl with properties that expose the differences between them, such as

public class MyUserControl
....

public bool IsColumn1ReadOnly{
    get{ return v_uc1.v_datagrid.Columns[1].IsReadOnly;}
    set {return v_uc1.v_datagrid.Columns[1].IsReadOnly = value;}
}

then in XAML you would instantiate the control like this:

<my:MyUserControl IsColumn1ReadOnly="True"/>
<my:MyUserControl IsColumn1ReadOnly="False"/>

其他提示

If you want to set a data grid column to read only in xaml do the following

 <DataGridTextColumn  IsReadOnly="True"/>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top