Note that there are some explanatory texts on larger screens.

plurals
  1. POInclude xaml element in xaml
    primarykey
    data
    text
    <p>I have two separate styles in which I am trying to include the same basic elements. For example, HorizontalButton has this style:</p> <pre><code>&lt;Style x:Key="HorizontalButton" TargetType="{x:Type custom:SampleButton}"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type custom:DispatchButton}"&gt; &lt;Border Name="outerBorder" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type custom:SampleGrid}}, Path=ActualWidth, Converter={StaticResource MathConverter}, ConverterParameter=x/7}"&gt; &lt;Border Name="innerBorder" BorderThickness="1" BorderBrush="WhiteSmoke" CornerRadius="1" Background="{TemplateBinding Background}"&gt; &lt;Grid Margin="2"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="4*"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="Auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="1*"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Orientation="Vertical" VerticalAlignment="Top"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{TemplateBinding Id}"&gt;&lt;/TextBlock&gt; &lt;TextBlock Text="{TemplateBinding Code}" Margin="4,0,0,0"&gt;&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;TextBlock Text="{TemplateBinding Address}" TextWrapping="Wrap"&gt;&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;Rectangle Grid.Row="1" Height="1" Margin="2,0,2,0" Stroke="DarkGray" /&gt; &lt;StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right"&gt; &lt;Grid&gt; &lt;Ellipse VerticalAlignment="Center" HorizontalAlignment="Center" Width="15" Height="15" Fill="{TemplateBinding SampleColor}" /&gt; &lt;TextBlock Foreground="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{TemplateBinding Sample}"&gt;&lt;/TextBlock&gt; &lt;/Grid&gt; &lt;Image Width="16" Height="16" Source="{TemplateBinding SymbolImage}" Margin="2,0,0,0" /&gt; &lt;/StackPanel&gt; &lt;ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Center" Name="content" /&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>And VerticalButton has this style:</p> <pre><code>&lt;Style x:Key="VerticalButton" TargetType="{x:Type custom:SampleButton}"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True" /&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type custom:DispatchButton}"&gt; &lt;Border Name="outerBorder" Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type custom:SampleGrid}}, Path=ActualHeight, Converter={StaticResource MathConverter}, ConverterParameter=x/7}"&gt; &lt;Border Name="innerBorder" BorderThickness="1" BorderBrush="WhiteSmoke" CornerRadius="1" Background="{TemplateBinding Background}"&gt; &lt;Grid Margin="2"&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="4*"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="Auto"&gt;&lt;/RowDefinition&gt; &lt;RowDefinition Height="1*"&gt;&lt;/RowDefinition&gt; &lt;/Grid.RowDefinitions&gt; &lt;StackPanel Orientation="Vertical" VerticalAlignment="Top"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;TextBlock Text="{TemplateBinding Id}"&gt;&lt;/TextBlock&gt; &lt;TextBlock Text="{TemplateBinding Code}" Margin="4,0,0,0"&gt;&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;TextBlock Text="{TemplateBinding Address}" TextWrapping="Wrap"&gt;&lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;Rectangle Grid.Row="1" Height="1" Margin="2,0,2,0" Stroke="DarkGray" /&gt; &lt;StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right"&gt; &lt;Grid&gt; &lt;Ellipse VerticalAlignment="Center" HorizontalAlignment="Center" Width="15" Height="15" Fill="{TemplateBinding SampleColor}" /&gt; &lt;TextBlock Foreground="{TemplateBinding Background}" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{TemplateBinding Sample}"&gt;&lt;/TextBlock&gt; &lt;/Grid&gt; &lt;Image Width="16" Height="16" Source="{TemplateBinding SymbolImage}" Margin="2,0,0,0" /&gt; &lt;/StackPanel&gt; &lt;ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Center" Name="content" /&gt; &lt;/Grid&gt; &lt;/Border&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>As you can see, outerBorder has different attributes set depending on whether or not the button is vertical or horizontal, but all of the inner elements from innerBorder inwards are identical. Is there a way I can do some kind of an include or reference in xaml so that I would only have to make changes to one instance of the inner elements to get the same results?</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.
    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