سؤال

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