Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try to make the UserControl have one top-level child, like a ContentControl for example, and apply the style to the ContentControl instead. That way, you wouldn't get recursions.</p> <p>EDIT : The below is from the original questioner......</p> <p>Here is my attempt to do what you suggest. For some reason my DataTriggers never apply the template.... not sure what I did wrong here.</p> <p>Here is the whole XAML trying it with a contained ContentControl : </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" x:Name="uc"&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 ContentControl}"&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 ContentControl}"&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;/UserControl.Resources&gt; &lt;ContentControl x:Name="ContentControl" &gt; &lt;!-- Style for the content control --&gt; &lt;ContentControl.Style&gt; &lt;Style TargetType="{x:Type ContentControl}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Value="False" Binding="{Binding ElementName=uc, Path=Flipped}"&gt; &lt;Setter Property="ContentControl.Template" Value="{StaticResource Up}" /&gt; &lt;/DataTrigger&gt; &lt;DataTrigger Value="True" Binding="{Binding ElementName=uc, Path=Flipped}"&gt; &lt;Setter Property="ContentControl.Template" Value="{StaticResource Down}" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/ContentControl.Style&gt; &lt;/ContentControl&gt; &lt;/UserControl&gt; </code></pre> <p>If I apply the style by hand like this : </p> <pre><code> &lt;ContentControl x:Name="ContentControl" Template="{StaticResource Up}"&gt; </code></pre> <p>It looks good! It's just that my datatriggers are not firing on the value of "Flipped"</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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