如果这是一个简单的问题,我深表歉意,但我一整天都在努力让它工作,我似乎无法弄清楚可能相当明显的事情。
我有一个带有自定义依赖属性“翻转”的用户控件。
在我的资源中,我有一个定义了两个触发器的样式,它将控件的模板设置为两个不同的值,具体取决于“翻转”是真还是假。
现在,我使用什么语法将样式应用于我正在创建的这个用户控件?
放入Style="{StaticResource EventStyle}"
标题UserControl
将不起作用。
这是我到目前为止所拥有的:
<UserControl x:Class="XDPClient.Controls.EventMarkerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Controls="clr-namespace:XDPClient.Controls"
mc:Ignorable="d"
d:DesignHeight="513" d:DesignWidth="695">
<UserControl.Resources>
<!-- Draw the user control right side up with this template -->
<ControlTemplate x:Key="Up" TargetType="{x:Type Controls:EventMarkerControl}">
<Grid>
<!-- Outline grid -->
<Path Stretch="Fill" Fill="#FFFFFFFF" Stroke="#FF6800FF" StrokeThickness="3" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeLineJoin="Miter" StrokeMiterLimit="4" Name="rect2985" RenderTransformOrigin="0,0">
<Path.Data>
<PathGeometry FillRule="Nonzero" Figures="M 0,250 L 0,50 L 150,50 L 200,-0.96 L 250,50 L 400,50 L 400,250 L 0,250z" />
</Path.Data>
</Path>
<!-- Placement of the content -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<Grid Grid.Row="1" Margin="3">
<ContentPresenter Grid.Row="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</Grid>
<Grid.BitmapEffect>
<DropShadowBitmapEffect />
</Grid.BitmapEffect>
</Grid>
</ControlTemplate>
<!-- Draw the user control flipped with this template -->
<ControlTemplate x:Key="Down" TargetType="{x:Type Controls:EventMarkerControl}">
<Grid>
<!-- Outline grid -->
<Path Stretch="Fill" Fill="#FFFFFFFF" Stroke="#FF6800FF" StrokeThickness="3" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeLineJoin="Miter" StrokeMiterLimit="4" Name="rect2985" RenderTransformOrigin="0,0">
<Path.Data>
<PathGeometry FillRule="Nonzero" Figures="M 0,250 L 0,50 L 150,50 L 200,-0.96 L 250,50 L 400,50 L 400,250 L 0,250z" />
</Path.Data>
<Path.RenderTransform>
<ScaleTransform ScaleX="-1" />
</Path.RenderTransform>
</Path>
<!-- Placement of the content -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<Grid Grid.Row="1" Margin="3">
<ContentPresenter Grid.Row="1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</Grid>
<Grid.BitmapEffect>
<DropShadowBitmapEffect />
</Grid.BitmapEffect>
</Grid>
</ControlTemplate>
<Style x:Key="EventStyle" TargetType="{x:Type Controls:EventMarkerControl}">
<Style.Triggers>
<Trigger Property="Flipped" Value="false">
<Setter Property="Template" Value="{StaticResource Up}" />
</Trigger>
<Trigger Property="Flipped" Value="true">
<Setter Property="Template" Value="{StaticResource Down}" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>