The answer is not to bind the GridItems via the containing control, your viewmodel should supply the List directly to where it is needed (the DataGrid).
Okay, so that probably requires extensive surgery to your model structure. If you just want to get it working, bind the DataGrid to the UserControl's GridItems dependency property:
Code:<UserControl x:Class="DataGrid.TestUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" x:Name="testUserControl"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock Text="Items:" Grid.Row="0" Margin="5"/> <DataGrid ItemsSource="{Binding GridItems, ElementName=testUserControl}" Grid.Row="1" Margin="5" AutoGenerateColumns="true" /> </Grid> </UserControl>




Reply With Quote