在数据模板中设置上下文菜单的数据上下文
下面是代码片段:
<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>
我需要将上下文菜单“xyzcontextmenu”的数据上下文设置为用户控件的数据上下文。
请尽快告诉我如何实现这一目标,
谢谢, 瑞塔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论