I’m working with WPF in C#.
My XAML looks as follows:
<ItemsControl x:Name="mygrid2" ItemsSource="{Binding Pallets , ElementName=root}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border x:Name="palletborder"
Background="{Binding PalletGroup.Color,
Converter={x:HtmlToBrushConverter.Instance}}">
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
As you can see, the grid consists of a group of squares (Border
s, in fact), which all get the same colour, defined elsewhere.
I would like to replace the x:Name
, which is currently the hardcoded word “palletborder”, into something useful, like Pallets.GetItem().Id
.
This is obviously wrong.
What is the correct syntax for this?
Edit:
I understand that it makes no sense using the x:Name
, but what about replacing the borders by labels? How can I get the items in different labels, like in the following example:
<ItemsControl x:Name="mygrid2" ItemsSource="{Binding Pallets , ElementName=root}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Pallets.<some_Item>.Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
2