Reputation: 23
I need to access data grid's columns collection in my model class but when i try this it says that the data grid's columns property doesn't has an accessible setter.
So are there any workarounds for accessing Columns property in model class?
My XAML code is like this :
<sdk:DataGrid RowDetailsVisibilityMode="VisibleWhenSelected" Columns="{Binding GridColumns, Mode=TwoWay}"
AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Single"
ClipboardCopyMode="ExcludeHeader" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="0,0,0,27" HeadersVisibility="Column" Grid.Row="1"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
ItemsSource="{Binding DataList, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" >
Upvotes: 1
Views: 283
Reputation: 4774
You can`t bind to Columns
property because it`s not DependencyProperty
. So just add columns from code if you need to pass them from somewhere else. If they are not context dependent then assigning them in XAML would probably be better.
On a side note, "access data grid's columns collection in my model" sounds rather strange for MVVM. Normally model shouldn`t even know what`s a DataGrid
.
Upvotes: 1