Binding from a DataGrid column back to the root property of a view model?

I have the following XAML:

<UserControl.Resources>
    <local:MainPageViewModel x:Key="ViewModel" />
</UserControl.Resources>

<Grid x:Name="LayoutRoot" 
      DataContext="{Binding Source={StaticResource ViewModel}}">
    <sdk:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items}">
        <sdk:DataGrid.Columns>
            <sdk:DataGridTextColumn Header="ID" Binding="{Binding ID}" />
            <sdk:DataGridTextColumn Header="Name" Binding="{Binding Name}" />
            <sdk:DataGridCheckBoxColumn
                Header="Checkbox Column"
                Binding="{Binding Source={StaticResource ViewModel},
                                  Path=SomeBooleanProperty}"/>

        </sdk:DataGrid.Columns>
    </sdk:DataGrid>
</Grid>

So, basically, I want one of the columns (the flag column) to be bound to some property (SomeBooleanProperty), which is located directly in the ViewModel, unlike the property in one of the items in the Items collection. (Yes, this is a little far-fetched, but it comes to my problem.) The problem is that based on my testing, if you communicate through StaticResource, it seems that the value is not updated based on the firing of the INotifyPropertyChanged event. The original value is correct, but it never changes. I cannot figure out how to get the "exit" from the element binding and returning to the ViewModel due to the column binding.

, WPF RelativeBinding, FindAncestor. Silverlight. ?

+3
2

, . @TerenceJackson , , VM, . , , -, . , , . , , - , .

0

" ". LayoutRoot, , .

DataContext , .

.

<sdk:DataGridCheckBoxColumn
                Header="Checkbox Column"
                Binding="{Binding ElementName=LayoutRoot,
                                  Path=SomeBooleanProperty}"/>

, / CheckBoxColumn (, )

+3

Source: https://habr.com/ru/post/1774325/


All Articles