I have to display a data grid inside a node. One of the columns of that data grid should be a combo box column. Is there any sample for a something like that. My combo items doesn’t get updated properly. If someone can provide me with a sample code, much appreciated… URGENT as well
Have you seen the Entity Relationship sample (a.k.a. “ER Diagram”)? That uses a DataGrid in the Node DataTemplate, in GoSilverlightDemo. However, if you are targeting WPF, the sample was written to run in WPF 3.5 as well as WPF 4.0+, so it could not use DataGrid.
But if you simply copy that Node DataTemplate into GoWpfDemo from Silverlight, it just works in WPF 4! Here’s the XAML:
<DataTemplate x:Key="NodeTemplate">
<Border Background="Gray" BorderBrush="Gray" BorderThickness="2" CornerRadius="3"
go:Part.SelectionAdorned="True" go:Part.Resizable="True"
go:Node.FromSpot="AllSides" go:Node.ToSpot="AllSides"
go:Node.Location="{Binding Path=Data.Location, Mode=TwoWay}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" HorizontalAlignment="Center"
Text="{Binding Path=Data.Key}" FontWeight="Bold" />
<Button Grid.Column="1" Content="*" Click="Button_Click" />
</Grid>
<DataGrid Grid.Row="1" AutoGenerateColumns="False"
Background="White" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=Data.Items}">
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<go:NodePanel>
<go:NodeShape go:NodePanel.Figure="{Binding Path=Figure}"
Width="10" Height="10"
Fill="{Binding Path=Color}"
Stroke="Black" StrokeThickness="1" />
</go:NodePanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Border>
</DataTemplate>
There were no other changes – including no changes to the C# code.
Oh, I guess the Entity Relationship sample’s DataGrid does not use a ComboBox. I don’t remember if I have used a ComboBox in a DataGrid before, but that should not be an issue. Have you searched the web for advice on the particular problem you are encountering?