質問

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