I have this data grid xml code:
which is code for a window I am showing.Code:<Window x:Class="SourcicoProjectTest.RecipeListWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SourcicoProjectTest.code" mc:Ignorable="d" Title="RecipeListWindow" Height="450" Width="800" Loaded="Window_Loaded"> <Window.DataContext> <local:MainMVVM/> </Window.DataContext> <Window.Resources> <local:RecipeCountConverter x:Key="countConverter"/> </Window.Resources> <Grid> <DataGrid Margin="5, 5, 5, 5" SelectedItem="{Binding selectedRecipe}" ItemsSource="{Binding recipesList}" IsReadOnly="True" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Header="Recipe ID" Binding="{Binding ID}" /> <DataGridTextColumn Header="Recipe Name" Binding="{Binding name}" /> <DataGridTextColumn Header="Recipe Source" Binding="{Binding source}" /> <DataGridTextColumn Header="Num. of Ingredients" Binding="{Binding Path=ingredients.Count}" /> <DataGridTextColumn Header="Ingredients" Binding="{Binding Path=ingredients}" /> <DataGridTextColumn Header="Prep. Time" Binding="{Binding prepTime}" /> <DataGridTextColumn Header="Prep. Instructions" Binding="{Binding prepInstructions}" /> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button Content="Details"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Button Content="Delete"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> </Grid> </Window>
If you see, the selected item is of type Recipe which has a list of ingredients:
I want in one column to display ingredients.Count which is how many ingredients arecipe has.Code:ObservableCollection<Ingredient> ingredients
I tried with this but it shows 0:
What do I miss in my XAML code? Do I need to use ValueConverter class/interface to get the count from my list of ingredients?Code:<DataGridTextColumn Header="Num. of Ingredients" Binding="{Binding Path=ingredients.Count}" />


Reply With Quote
