none
Problem making a Trigger on the Tag property

    Question

  • Hi,

    I want the Height of a RowDefinition to be set to Auto when a property on some other object is false. I've tried to do that by binding that property to the Tag on the RowDefinition, and then using a Trigger on the Tag property, but unfortunately that doesn't work.
    Can someone please explain to me what's wrong with this xaml?:

    <Grid Grid.Column="0">
    <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="Auto"/>
    <RowDefinition Tag="{Binding ElementName=bottomPane, Path=IsOpen}"
    Height="{Binding Source={xTongue Tiedtatic presenter:UserSettings.Instance}, Path=BottomPaneHeightWhenOpen, Mode=TwoWay}">
    <RowDefinition.Style>
    <Style TargetType="{x:Type RowDefinition}">
    <Style.Triggers>
    <Trigger Property="Tag" Value="False">
    <Setter Property="Height" Value="Auto"/>
    </Trigger>
    </Style.Triggers>
    </Style>
    </RowDefinition.Style>
    </RowDefinition>
    </Grid.RowDefinitions>

    <view:MainArea Grid.Row="0" x:Name="mainArea"/>

    <GridSplitter Grid.Row="1" Style="{StaticResource HorizontalSplitter}" Visibility="{Binding ElementName=bottomPane,
    Path=IsOpen, Converter={StaticResource BooleanToVisibilityConverter}}"/>

    <view:BottomPane Grid.Row="2" x:Name="bottomPane"/>

    </Grid>

    I've set a converter on the RowDefinition Tag binding to make sure it's getting the correct value, and it is. So the Trigger is being ignored.

    Best Regards,
    Gustavo Guerra


    Saturday, March 29, 2008 6:52 PM

Answers

  • This example works:

     

    Code Snippet

    <Window x:Class="TriggerExample.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:sys="clr-namespace:System;assembly=mscorlib"

    Title="TriggerExample" Height="300" Width="300">

    <Grid>

     

    <Grid.RowDefinitions>

    <RowDefinition Height="*"/>

    <RowDefinition Tag="{Binding ElementName=bottomPane, Path=IsChecked}">

    <RowDefinition.Style>

    <Style TargetType="{x:Type RowDefinition}">

    <Setter Property="Height" Value="200"/>

    <Style.Triggers>

    <Trigger Property="Tag">

    <Trigger.Value>

    <sys:Boolean>False</sys:Boolean>

    </Trigger.Value>

    <Setter Property="Height" Value="Auto"/>

    </Trigger>

    </Style.Triggers>

    </Style>

    </RowDefinition.Style>

    </RowDefinition>

    </Grid.RowDefinitions>

     

    <TextBlock Grid.Row="0"

    x:Name="mainArea"

    Background="LightSkyBlue">This is main area...</TextBlock>

     

    <CheckBox Grid.Row="1"

    x:Name="bottomPane">Set height to 200</CheckBox>

    </Grid>

    </Window>

     

     

    And i think the only problem was that the following syntax:

    Code Snippet

    <Trigger Property="Tag" Value="True">

     

    forces XamlParser to assign String (not Boolean) value "True" (or "False") to property "Tag".

     

     

    Hope this helps.

    Saturday, March 29, 2008 7:54 PM

All replies

  • This local value:

     

    Code Snippet

    <RowDefinition Tag="{Binding ElementName=bottomPane, Path=IsOpen}"
    Height="{Binding Source={x:Static presenter:UserSettings.Instance}, Path=BottomPaneHeightWhenOpen, Mode=TwoWay}">

     

     

    has always higher precedence then value set by style trigger:

     

    Code Snippet

    <Style.Triggers>
    <Trigger Property="Tag" Value="False">
    <Setter Property="Height" Value="Auto"/>
    </Trigger>
    </Style.Triggers>

     

     

    There are two solutions:

     

    1. Convert local value definition to style setter definition.

    2. Convert style trigger definition to element trigger definition.

     

     

    Good luck.

    Saturday, March 29, 2008 7:10 PM
  • I tryed Nº1.

     

    This didin't work:

     

    <RowDefinition

    Tag="{Binding ElementName=bottomPane, Path=IsOpen}">

    <RowDefinition.Style>

    <Style TargetType="{x:Type RowDefinition}">

    <Setter Property="Height"

    Value="{Binding Source={x:Static presenter:UserSettings.Instance},

    Path=BottomPaneHeightWhenOpen,

    Converter={StaticResource DoubleToGridLengthConverter},

    Mode=TwoWay}"/>

    <Style.Triggers>

    <Trigger Property="Tag" Value="False">

    <Setter Property="Height" Value="Auto"/>

    </Trigger>

    </Style.Triggers>

    </Style>

    </RowDefinition.Style>

    </RowDefinition>

    </Grid.RowDefinitions>

     

    And this was even worse as now it always defaults to *:

    <RowDefinition

    Tag="{Binding ElementName=bottomPane, Path=IsOpen}">

    <RowDefinition.Style>

    <Style TargetType="{x:Type RowDefinition}">

    <Style.Triggers>

    <Trigger Property="Tag" Value="True">

    <Setter Property="Height"

    Value="{Binding Source={x:Static presenter:UserSettings.Instance},

    Path=BottomPaneHeightWhenOpen,

    Converter={StaticResource DoubleToGridLengthConverter},

    Mode=TwoWay}"/>

    </Trigger>

    <Trigger Property="Tag" Value="False">

    <Setter Property="Height" Value="Auto"/>

    </Trigger>

    </Style.Triggers>

    </Style>

    </RowDefinition.Style>

    </RowDefinition>

     

    So, my triggers keep being ignored.

     

    I don't know what's Nº2. What's an element trigger definition?

     

    Best Regards,

    Gustavo Guerra

    Saturday, March 29, 2008 7:29 PM
  • This example works:

     

    Code Snippet

    <Window x:Class="TriggerExample.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:sys="clr-namespace:System;assembly=mscorlib"

    Title="TriggerExample" Height="300" Width="300">

    <Grid>

     

    <Grid.RowDefinitions>

    <RowDefinition Height="*"/>

    <RowDefinition Tag="{Binding ElementName=bottomPane, Path=IsChecked}">

    <RowDefinition.Style>

    <Style TargetType="{x:Type RowDefinition}">

    <Setter Property="Height" Value="200"/>

    <Style.Triggers>

    <Trigger Property="Tag">

    <Trigger.Value>

    <sys:Boolean>False</sys:Boolean>

    </Trigger.Value>

    <Setter Property="Height" Value="Auto"/>

    </Trigger>

    </Style.Triggers>

    </Style>

    </RowDefinition.Style>

    </RowDefinition>

    </Grid.RowDefinitions>

     

    <TextBlock Grid.Row="0"

    x:Name="mainArea"

    Background="LightSkyBlue">This is main area...</TextBlock>

     

    <CheckBox Grid.Row="1"

    x:Name="bottomPane">Set height to 200</CheckBox>

    </Grid>

    </Window>

     

     

    And i think the only problem was that the following syntax:

    Code Snippet

    <Trigger Property="Tag" Value="True">

     

    forces XamlParser to assign String (not Boolean) value "True" (or "False") to property "Tag".

     

     

    Hope this helps.

    Saturday, March 29, 2008 7:54 PM
  • Thank you very much

    Saturday, March 29, 2008 7:58 PM
  • Sorry about element triggers.

    RowDefinition is not a FrameworkElement and thus does not support these triggers.

    Saturday, March 29, 2008 8:03 PM