1
我窗口的DataContext是一個IDictionary>。WPF/Xaml ContextMenu ItemContainerStyle行爲
誰能向我解釋爲什麼這工作得很好:
<Style x:Key="MenuItemStyle">
<Setter Property="MenuItem.Header" Value="{Binding Ticker}"/>
</Style>
<Style x:Key="ContextMenuStyle">
<Setter Property="MenuItem.Header" Value="{Binding Key}"/>
<Setter Property="MenuItem.ItemsSource" Value="{Binding Value}"/>
<Setter Property="MenuItem.ItemContainerStyle" Value="{StaticResource MenuItemStyle}"/>
</Style>
<ContextMenu ItemContainerStyle="{StaticResource ContextMenuStyle}" ItemsSource="{Binding Quotes}" />
但這並不:
<Style TargetType="{x:Type ContextMenu}" x:Key="ContextMenuStyle">
<Setter Property="MenuItem.Header" Value="{Binding Key}"/>
<Setter Property="MenuItem.ItemsSource" Value="{Binding Value}"/>
<Setter Property="MenuItem.ItemContainerStyle">
<Setter.Value>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Header" Value="{Binding Ticker}"/>
</Style>
</Setter.Value>
</Setter>
</Style>
<ContextMenu ItemContainerStyle="{StaticResource ContextMenuStyle}" ItemsSource="{Binding Quotes}" />
編輯:如果我刪除T'argetType = 「{X:輸入文本菜單}」 ',它工作正常。然而我不清楚爲什麼。
感謝