2015-12-22 70 views
0

我正在嘗試自定義功能區按鈕。我自定義了一個ribbonbutton,但只顯示空白的白色窗口

我畫了兩個橢圓,箭頭指向下方。我把它放在Windows資源中,這樣我就可以在整個項目中使用這種風格,通過它的關鍵名稱「RibbonButtonControlTemplateTest」來引用它。但是,當我執行下面的代碼時,我看到顯示的是一個空白的白色窗口,爲什麼?

<Window x:Class="WpfApplication5.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" 
    xmlns:local="clr-namespace:WpfApplication5" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 

<Window.Resources> 
    <ControlTemplate x:Key="RibbonButtonControlTemplateTest" TargetType="{x:Type RibbonButton}"> 
     <Grid> 
      <Ellipse> 
       <Ellipse.Fill> 
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> 
         <GradientStop Offset="0" Color="Green"/> 
         <GradientStop Offset="0.5" Color="White"/> 
         <GradientStop Offset="1" Color="Green"/> 
        </LinearGradientBrush> 
       </Ellipse.Fill> 
      </Ellipse> 
      <Ellipse Margin="10"> 
       <Ellipse.Fill> 
        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0"> 
         <GradientStop Offset="0" Color="Transparent"/> 
         <GradientStop Offset="0.5" Color="White"/> 
         <GradientStop Offset="1" Color="Transparent"/> 
        </LinearGradientBrush> 
       </Ellipse.Fill> 
      </Ellipse> 
      <ed:BlockArrow HorizontalAlignment="Stretch" Height="Auto" Margin="28.212,26.557,29.404,19.757" Orientation="Down" Width="Auto"> 
       <ed:BlockArrow.Fill> 
        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> 
         <GradientStop Offset="0" Color="Green"/> 
         <GradientStop Offset="0.5" Color="White"/> 
         <GradientStop Offset="1" Color="Green"/> 
        </LinearGradientBrush> 
       </ed:BlockArrow.Fill> 
      </ed:BlockArrow> 
     </Grid> 
    </ControlTemplate> 
</Window.Resources> 

<Grid> 
    <Grid x:Name="gridLeft" HorizontalAlignment="Left" Width="253.714"> 
     <RibbonButton x:Name="ribbonButton" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" 
         Content="{StaticResource RibbonButtonControlTemplateTest}"> 
     </RibbonButton> 
    </Grid> 
    <Grid x:Name="gridRight" HorizontalAlignment="Right" Width="253.714"> 
    </Grid> 

</Grid> 

回答

1

使用內容,而不是模板。嘗試改變這種代碼:

<RibbonButton x:Name="ribbonButton" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" 
         Content="{StaticResource RibbonButtonControlTemplateTest}"> 
     </RibbonButton> 

要:

<RibbonButton x:Name="ribbonButton" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" 
         Template="{StaticResource RibbonButtonControlTemplateTest}"> 
     </RibbonButton>