ItemsControl Bindings
Posted: 27 Oct 2024, 12:55
Good day,
I'm sure this is a very trivial question, but I couldn't find a similar question here on the forum and the documentation for ItemControl is a bit sparse.
I'm simply trying to create a quickly put together hotbar. I opted for an ItemsControl with a horizontally oriented stackpanel as ItemsPanel.
Here's The XAML:
I'm a WPF developer, and the expected behaviour would be, that the generated controls have their DataContext automatically set to the current item during the iteration.
However, my Binding seems to fail:
Any directions are apreciated!
I'm sure this is a very trivial question, but I couldn't find a similar question here on the forum and the documentation for ItemControl is a bit sparse.
I'm simply trying to create a quickly put together hotbar. I opted for an ItemsControl with a horizontally oriented stackpanel as ItemsPanel.
Here's The XAML:
Code: Select all
<!-- DataContext for UserControl is set in code behind -->
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="2"
Margin="0 10 0 0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Content="DBG"
Height="50"
Width="50"
Command="{Binding DebugCommand}"/>
<Border CornerRadius="8"
BorderThickness="1"
BorderBrush="Silver"
Background="DimGray"
Grid.Column="1"
Padding="0 5">
<ItemsControl Items="{Binding HotBar.Slots}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type Slot}">
<Border Height="50"
Width="50"
Margin="5 0"
Background="Gray"
BorderThickness="1"
BorderBrush="Silver"
ToolTip="{Binding Content.ItemName}"
CornerRadius="5" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>
</Grid>
</Grid>
However, my Binding seems to fail:
Code: Select all
[NOESIS] Binding failed: Path=Content.ItemName, Source=BindingExpression(''), Target=Border(''), TargetProperty=ToolTipService.ToolTip