我正在尝试自定义功能区按钮。
我画了两个椭圆,箭头指向下方。我把它放在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>
答案 0 :(得分: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>