Home > Mobile >  WPF new column cell for each itemsource in itemscontrol
WPF new column cell for each itemsource in itemscontrol

Time:03-25

I have a ObservableCollection<string> in viewModel, and I have set this as itemsource of an ItemsControl.

Code

<ItemsControl ItemsSource="{Binding NameofCollection}">
</ItemsControl>

It is appearing normally, 1 column with all items in the collection appearing in a new line.

Now, I want to have a new column, next to the current column, which should display a fixed string("yes", for example) for all the items.

So, if I have 5 elements in collection, the new column should contain 5 cells, each containing a fixed string "yes".

Struggling to implement it myself.

CodePudding user response:

You can do it this way:

            <ItemsControl ItemsSource="{Binding NameofCollection}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Column="0" Text="{Binding}"/>
                            <TextBlock Grid.Column="1" Text="yes"/>
                        </Grid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
  • Related