How to set d: DataContext d: DesignInstance in a DataGrid
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 above xaml, I canβt get the development time d: the DataContext DesignInstance links are correct both for binding the DataGrid itself, and with bindings of specific columns.
If I include the following snippet in the DataGrid (as above for xaml), then the DataGridTextColumns works, and I get intellisense for the column bindings:
d:DataContext="{d:DesignInstance vm:Episode} But now the DataGrid binding of the intellisense binding no longer works. If I remove the fragment over the opposite, it will happen: the Intellisense for DataGrid binding works, but the column bindings do not.
To be clear, this is only a development-time issue. Everything is working fine.
Setting the d:DataContext changes the design time to use the new Episode created using the default constructor. You may need to set IsDesignTimeCreatable to true.
d:DataContext="{d:DesignInstance vm:Episode, d:IsDesignTimeCreatable=True}" However, I expect your problem is that Episode is an element type and does not have an EpisodesView property. You will need to set the data grid time data context to the Episodes collection