开发者

Set the datacontext of the context menu with in a data template

Below is the code snippet:

            <ResourceDictionary>

                *   *   *


                <DataTemplate x:Key="xyzTemplate" DataType="arguments" PresentationTraceSources.TraceLevel="High">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock  Text="(" VerticalAlignment="Center" Margin="2,0,2,0" FontSize="18" 
                                   x:Name="firstbrace" Visibility="Collapsed">
                        </TextBlock>
                          <ItemsControl ItemsSource="{Binding}" KeyboardNavigation.IsTabStop="False">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <StackPanel Orientation="Horizontal"></StackPanel>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel  Orientation="Horizontal">
                                        <TextBlock 
                          开发者_开发百科                  FontSize="11" VerticalAlignment="Bottom" Margin="1,0,1,2" Text=" , " Width="auto" Name="Comma" Height="auto" >
                                        </TextBlock>


                                                <ComboBox   x:Name="blockCombo" Visibility="Collapsed" ItemsSource="{Binding XPath=.//value}" >
                                                <ComboBox.ContextMenu>
                                                <ContextMenu x:Name="xyzcontextMenu" 
                                                     DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.DataContext}"
                                                             >
                                                    <MenuItem 
                                                     Command="{Binding Path=xyzcommand}"                                                         
                                                      Header="MenuItem1" >

                                                    </MenuItem>
                                                </ContextMenu>
                                            </ComboBox.ContextMenu>
                                                </ComboBox>                                         

I need to set the data context of the context menu "xyzcontextmenu" as the data context of the UserControl.

Please let me know asap how can I achieve this

Thanks, Shwetha

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜