Xaml 在Contextmenu上找不到RelativeSource属性
我的xaml中有以下上下文菜单:Xaml 在Contextmenu上找不到RelativeSource属性,xaml,contextmenu,relativesource,Xaml,Contextmenu,Relativesource,我的xaml中有以下上下文菜单: <ContextMenu ItemsSource="{Binding RSPContextMenuCommands}"> <ContextMenu.ItemContainerStyle> <Style TargetType="{x:Type MenuItem}">
<ContextMenu ItemsSource="{Binding RSPContextMenuCommands}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=DataContext.ShowASPCommand}" />
<Style.Triggers>
</DataTrigger>
<DataTrigger Binding="{Binding SpName}" Value="ASP">
<Setter Property="Header" Value="Show Additional Service Providers" />
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=DataContext.TransferCommand}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContextMenu.ItemContainerStyle>
<ContextMenu.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,0,0" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PhoneNumber, PresentationTraceSources.TraceLevel=High}" />
</StackPanel>
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
其中,RSPContextMenuCommands是Schedule(类)类型的集合。计划中有PhoneNumber属性。TransferCommand与声明RSPContextMenuCommand的级别相同。我收到的是ShowASPCommand和TransferCommand,但不是电话号码。我尝试了各种相对资源组合,但都不起作用。什么是合适的相对资源。还尝试了
RelativeSource={relativesourcefindancestor,AncestorType={x:Type ContextMenu}},Path=PhoneNumber
解决方法。我将ItemTemplate移动到ItemContainerStyle上方
<ContextMenu ItemsSource="{Binding RSPContextMenuCommands}">
<ContextMenu.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding PhoneNumber}" />
</StackPanel>
</DataTemplate>
</ContextMenu.ItemTemplate>
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=DataContext.ShowASPCommand, PresentationTraceSources.TraceLevel=High}" />
<Style.Triggers>
<DataTrigger Binding="{Binding SpName}" Value="ASP">
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=DataContext.TransferCommand}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
Setter Property=“Command”Value=“{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}},Path=DataContext.ShowASPCommand,presentationontracesources.TraceLevel=High}”/>
但是,如果有任何人能为我提供有关相对资源方法的适当文档。我将非常感激。:-) 为TransferCommand定义RelativeSource后,我的绑定级别位于声明RSPContextMenuCommand的类中。我想再次进入RSPContextMenuCommand。请帮帮我。