2014-09-21 192 views
0

不適用我已經創建的自定義控制,並在樣式菜單項不工作我已經使用了支持算法FMP鍵應用該樣式風格菜單項

通用XAML代碼片斷

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:WpfApplication3"> 

    <Style x:Key="MenuItemStyle" TargetType="{x:Type MenuItem}"> 
     <Setter Property="Height" Value="60"/> 
     <Setter Property="Background" Value="Red"/> 
    </Style> 

    <Style BasedOn="{StaticResource ResourceKey=MenuItemStyle}" TargetType="{x:Type MenuItem}"/> 
    <Style TargetType="{x:Type local:CustomControl1}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:CustomControl1}"> 
        <Grid x:Name="MainGrid"> 
         <Menu> 
          <MenuItem Header="File" /> 
         </Menu> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ResourceDictionary> 

樣式不申請菜單項,同時增加了風格類似下面代碼工作,這個使用基於,因爲在我的scnorio我必須使用多個的菜單項

回答

0

你這裏有兩種選擇

012如何實現

從風格

<Style TargetType="{x:Type MenuItem}"> 
    <Setter Property="Height" Value="60"/> 
    <Setter Property="Background" Value="Red"/> 
</Style> 

這將這種風格適用於範圍內的所有菜單項拔出鑰匙。

注意:如果您發現它不適合您,請嘗試在Menu的資源中定義樣式。


或直接套用樣式的菜單項留下鑰匙風格

<MenuItem Header="File" Style="{StaticResource MenuItemStyle}"/> 

這將樣式應用到所需的菜單項目只有


這種風格不起任何作用

<Style BasedOn="{StaticResource ResourceKey=MenuItemStyle}" TargetType="{x:Type MenuItem}"/>