Sorry for the not so very general question...
I have a ListView that I have to fill from code behind, and this ListView also need to get its GridViewColumn's from code behind.
For strings it wasn't hard to make the connection, but now I wan't to create a Ellipse that represents a Boolean value in the ListView.
The code in XAML is rather easy, but I fail at converting it to c# code.
Here is parts of the XMAL code:
<ResourceDictionary>
<BooleanToVisibilityConverter x:Key="BoolToVisibility" />
<DataTemplate x:Key="templateAdmin">
<DockPanel>
<Ellipse Width="8" Height="8" Visibility="{Binding Path=isAdmin, Converter={StaticResource BoolToVisibility}}" Fill="Black"/>
</DockPanel>
</DataTemplate>
</ResourceDictionary>
<ListView>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding LastName}" Header="Last Name"/>
<GridViewColumn CellTemplate="{StaticResource templateAdmin}"
<GridViewColumnHeader">
<TextBlock Text="S"/>
</GridViewColumnHeader>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
And by now I have gotten this far: XAML:
<local:SortableListView >
<ListView.View>
<GridView x:Name="GroupListGridView" />
</ListView.View>
</local:SortableListView>
And in code I have a Collection<GridViewColumn> GridViewColumns
that I loop throug and add all items to the GroupListGridView
. And I have a function to fill the GridViewColumns
collection:
private void CreateGridViews()
{
//Creating the Text was easy!
GridViewColumns.add(new GridViewColumn(){ Header = "LastName", DisplayMemberBinding = new Binding("LastName") });
//Creating the Ellipse was harder!
GridViewColumn gvc = new GridViewColumn();
DataTemplate dt = new DataTemplate();
gvc.DisplayMemberBinding = new Binding("isAdmin");
FrameworkElementFactory fef = new FrameworkElementFactory(typeof(Ellipse));
fef.SetValue(Ellipse.WidthProperty, 8.0D);
fef.SetValue(Ellipse.HeightProperty, 8.0D);
fef.SetValue(Ellipse.FillProperty, new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Black));
//I'm guessing that somewhere here there should be some binding to the visibility property and some sort of conversion done... But I can't figure out how!
dt.VisualTree = fef;
gvc.CellTemplate = dt;
GridViewColumns.Add(gvc);
}
I don't think that I'm that far of... Just that I can't figure out those last steps!