Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I apply a style resource to a usercontrol where that style uses triggers to apply templates?
    primarykey
    data
    text
    <p>I apologize if this is an easy question, but I have been trying to get this to work all day and I can't seem to figure something out that is fairly obvious probably.</p> <p>I have a user control with a custom dependency property "Flipped".</p> <p>In my resource I have a Style with two triggers defined, that set the template of the control to two different values depending on if 'Flipped' is true of false.</p> <p>Now, what syntax do I use to apply the style to this user control I am creating?</p> <p>Putting <code>Style="{StaticResource EventStyle}"</code> in the header of the <code>UserControl</code> won't work.</p> <p>Here is what I have so far : </p> <pre><code>&lt;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"&gt; &lt;UserControl.Resources&gt; &lt;!-- Draw the user control right side up with this template --&gt; &lt;ControlTemplate x:Key="Up" TargetType="{x:Type Controls:EventMarkerControl}"&gt; &lt;Grid&gt; &lt;!-- Outline grid --&gt; &lt;Path Stretch="Fill" Fill="#FFFFFFFF" Stroke="#FF6800FF" StrokeThickness="3" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeLineJoin="Miter" StrokeMiterLimit="4" Name="rect2985" RenderTransformOrigin="0,0"&gt; &lt;Path.Data&gt; &lt;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" /&gt; &lt;/Path.Data&gt; &lt;/Path&gt; &lt;!-- Placement of the content --&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="1*" /&gt; &lt;RowDefinition Height="4*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid Grid.Row="1" Margin="3"&gt; &lt;ContentPresenter Grid.Row="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;Grid.BitmapEffect&gt; &lt;DropShadowBitmapEffect /&gt; &lt;/Grid.BitmapEffect&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;!-- Draw the user control flipped with this template --&gt; &lt;ControlTemplate x:Key="Down" TargetType="{x:Type Controls:EventMarkerControl}"&gt; &lt;Grid&gt; &lt;!-- Outline grid --&gt; &lt;Path Stretch="Fill" Fill="#FFFFFFFF" Stroke="#FF6800FF" StrokeThickness="3" StrokeStartLineCap="Flat" StrokeEndLineCap="Flat" StrokeLineJoin="Miter" StrokeMiterLimit="4" Name="rect2985" RenderTransformOrigin="0,0"&gt; &lt;Path.Data&gt; &lt;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" /&gt; &lt;/Path.Data&gt; &lt;Path.RenderTransform&gt; &lt;ScaleTransform ScaleX="-1" /&gt; &lt;/Path.RenderTransform&gt; &lt;/Path&gt; &lt;!-- Placement of the content --&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="1*" /&gt; &lt;RowDefinition Height="4*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Grid Grid.Row="1" Margin="3"&gt; &lt;ContentPresenter Grid.Row="1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;Grid.BitmapEffect&gt; &lt;DropShadowBitmapEffect /&gt; &lt;/Grid.BitmapEffect&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;Style x:Key="EventStyle" TargetType="{x:Type Controls:EventMarkerControl}"&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="Flipped" Value="false"&gt; &lt;Setter Property="Template" Value="{StaticResource Up}" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="Flipped" Value="true"&gt; &lt;Setter Property="Template" Value="{StaticResource Down}" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/UserControl.Resources&gt; </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload