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?

Was it helpful?

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

OTHER TIPS

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

 <DataGridTextColumn  IsReadOnly="True"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top