OFGemini
asked on
ItemsPresenter bind CommandParameter to item
I have an ItemsPresenter with a context menu. In the context menu there is one menuitem and I want to bind the CommandParameter of the MenuItem to the Item inside of the ItemsPresenter. But I'm having trouble getting to the Item. How Do I bind the CommandParameter to the Item? The item is a ViewModel Object I created.
<ItemsPresenter Margin="24,0,0,0" >
<ItemsPresenter.ContextMen u>
<ContextMenu>
<MenuItem Header="Remove file from OCR list" Command="{x:Static commands:OCRCommands.Remov eFile}" CommandParameter="{Binding }">
<MenuItem.Icon>
<Image Source="/ThemeManager;comp onent/Imag es/Delete - Copy.png" Width="15" Margin="5"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ItemsPresenter.ContextMe nu>
</ItemsPresenter>
<ItemsPresenter Margin="24,0,0,0" >
<ItemsPresenter.ContextMen
<ContextMenu>
<MenuItem Header="Remove file from OCR list" Command="{x:Static commands:OCRCommands.Remov
<MenuItem.Icon>
<Image Source="/ThemeManager;comp
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ItemsPresenter.ContextMe
</ItemsPresenter>
<GroupStyle x:Key="groupItemStyle">
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True" Background="AliceBlue">
<Expander.Header>
<DockPanel>
<TextBlock Text="{Binding Path=Name}" Margin="5,0,0,5" Width="200" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="(" />
<TextBlock Text="{Binding Path=ItemCount}" />
<TextBlock Text=" items)" />
</StackPanel>
</DockPanel>
</Expander.Header>
<Expander.Content>
<Border Background="White" Margin="2" CornerRadius="3">
<ItemsPresenter Margin="24,0,0,0" >
<ItemsPresenter.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove file from OCR list" Command="{x:Static commands:OCRCommands.RemoveFile}" CommandParameter="{Binding}">
<MenuItem.Icon>
<Image Source="/Dms.ThemeManager;component/Images/Delete - Copy.png" Width="15" Margin="5"/>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</ItemsPresenter.ContextMenu>
</ItemsPresenter>
</Border>
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've added screenshot of when my Execute Command Handler is called. When I bind using CommandParameter="{Binding
In Debug mode I looked inside this object and I see it as a collection and the Item I really wanted to bind to is present in the collection. My question is how to I bind directly to my object via XAML.
I've attached a screenshot showing what I got and What I'm trying to get.
Capture.PNG