Link to home
Start Free TrialLog in
Avatar of OFGemini
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.ContextMenu>
                                                                        <ContextMenu>
                                                                           <MenuItem Header="Remove file from OCR list" Command="{x:Static commands:OCRCommands.RemoveFile}"   CommandParameter="{Binding}">
                                                                                <MenuItem.Icon>
                                                                                    <Image Source="/ThemeManager;component/Images/Delete - Copy.png" Width="15"  Margin="5"/>
                                                                                </MenuItem.Icon>
                                                                            </MenuItem>
                                                                        </ContextMenu>
                                                                    </ItemsPresenter.ContextMenu>
                                                                </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>

Open in new window

Avatar of OFGemini
OFGemini

ASKER

Hello,

I've added screenshot of when my Execute Command Handler is called.  When I bind using CommandParameter="{Binding}"  I get an object of the MS.Internal.DataCollectionViewGroupInternal.
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
ASKER CERTIFIED SOLUTION
Avatar of OFGemini
OFGemini

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial