How to set d:DataContext d:DesignInstance on DataGrid

Viewed 5448

The xaml:

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <TextBox VerticalAlignment="Center" FocusManager.IsFocusScope="True" Grid.ColumnSpan="2" Name="SearchTextBox" Text="{Binding Path=SearchTerm.Value, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource FontStyle}" KeyUp="SearchTextBoxKeyUp" />

    <DataGrid Grid.Row="1" ItemsSource="{Binding Path=EpisodesView, Mode=TwoWay}" MouseDoubleClick="ListViewDoubleClick" Style="{StaticResource FontStyle}" KeyUp="ListViewKeyup" Name="EpisodeList" AutoGenerateColumns="False" IsReadOnly="True"
              d:DataContext="{d:DesignInstance vm:Episode}">
        <DataGrid.Columns>
            <DataGridTextColumn Header="File" Binding="{Binding File.Name}" />
            <DataGridTextColumn Header="Age" Binding="{Binding PrettyAge}" SortMemberPath="Age" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>
</Window>

In the DataGrid at the bottom of the xaml above I am unable to BOTH get the design time d:DataContext DesignInstance references to be correct for both the binding of the DataGrid itself and the bindings of the specific columns.

If I include the the following snippet in DataGrid (as the xaml above) the DataGridTextColumns works, and I get intellisense for the column bindings:

d:DataContext="{d:DesignInstance vm:Episode}

But now the DataGrid binding intellisense no longer work. If I remove the snippet above the reverse happens: Intellisense for DataGrid binding works, but the column bindings don't.

To make it clear, this is only a design time problem. Everything works fine runtime.

1 Answers
Related