Question

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?

Était-ce utile?

La solution

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"/>

Autres conseils

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

 <DataGridTextColumn  IsReadOnly="True"/>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top