ivan_b
Topic Author
Posts: 87
Joined: 22 Jul 2015, 12:57

Ignoring unsupported property 'Visibility'

20 Jan 2016, 19:23

Inside a DataTemplate of a ListBoxItem I am trying to set DataTrigger but I am getting the warning " Ignoring unsupported property 'Visibility' ". It also happens whit the Text property of a TextBlock.
Here is part of the code
          <ListBox.ItemTemplate>
              <DataTemplate>
                <DataTemplate.Triggers>
                  <DataTrigger  Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
                     <Setter TargetName="RevisionsList" Property="Visibility" Value="Visible" />
                  </DataTrigger>
                  <DataTrigger  Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="False">
                     <Setter TargetName="RevisionsList" Property="Visibility" Value="Collapsed" />
                  </DataTrigger>                              
                </DataTemplate.Triggers>
Am I doing something wrong or this behaviour is not allowed?

Thank you
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Ignoring unsupported property 'Visibility'

21 Jan 2016, 19:59

I need a bit more of information.
Could you please post also the VisualTree of the DataTemplate?
I guess it contains an element named RevisionsList, right?
 
ivan_b
Topic Author
Posts: 87
Joined: 22 Jul 2015, 12:57

Re: Ignoring unsupported property 'Visibility'

21 Jan 2016, 20:20

Of course. Yes, it contains an element with that name.
         <ListBox.ItemTemplate>
              <DataTemplate>
                <DataTemplate.Triggers>
                  <DataTrigger  Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
                     <Setter TargetName="RevisionsList" Property="Visibility" Value="Visible" />
                  </DataTrigger>
                  <DataTrigger  Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="False">
                     <Setter TargetName="RevisionsList" Property="Visibility" Value="Collapsed" />
                  </DataTrigger>                       
                </DataTemplate.Triggers>
              <StackPanel>
                    <Grid Height="30" >
                      <Grid.ColumnDefinitions>
                          <ColumnDefinition Width="2*" x:Name="NameCell"/>
                          <ColumnDefinition Width="1*" x:Name="PlayersCell"/>
                          <ColumnDefinition Width="1*" x:Name="FitnessCell"/>
                          <ColumnDefinition Width="1*" x:Name="TechnicsCell"/>
                          <ColumnDefinition Width="1*" x:Name="TacticsCell"/>
                          <ColumnDefinition Width="1*" x:Name="FunCell"/>
                          <ColumnDefinition Width="1*" x:Name="TypeCell"/>
                      </Grid.ColumnDefinitions>
                      <Label Grid.Column="0" x:Name="Test" Content="{Binding Scene.Name}" VerticalAlignment="Center"  Width="{Binding ActualWidth, ElementName=NameColumn}" HorizontalAlignment="Center" />
                      <Label Grid.Column="1" Content="{Binding Path=Scene.Players, Converter={StaticResource PlayersToTextConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                      <Label Grid.Column="2" Content="{Binding Path=Scene.Fitness, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                      <Label Grid.Column="3" Content="{Binding Path=Scene.Technics, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                      <Label Grid.Column="4" Content="{Binding Path=Scene.Tactics, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                      <Label Grid.Column="5" Content="{Binding Path=Scene.Fun, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                      <Viewbox Grid.Column="6" Width="24" Height="24" >
                        <Path x:Name="Icon" Fill="Black" Data="{StaticResource Animations}" />
                      </Viewbox>
                    </Grid>
                 <ListBox x:Name="RevisionsList" Visibility="Visible" ItemsSource="{Binding Revisions}" SelectedItem="{Binding SelectedRevision}" >
                  <ListBox.ItemTemplate>
                    <DataTEmplate>
                      <TextBlock Text="{Binding Name}"></TextBlock>
                    </DataTEmplate>
                  </ListBox.ItemTemplate>
                 </ListBox>
                </StackPanel>    
              </DataTemplate>
            </ListBox.ItemTemplate>          
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Ignoring unsupported property 'Visibility'

21 Jan 2016, 21:02

As I imagined, you are specifying the VisualTree of the template after the Triggers, so elements are not registered yet. If you try your xaml in a WPF editor (like Kaxaml) it will complain about a missing reference to an object too.

Just declare first the VisualTree and later the Triggers:
<ListBox.ItemTemplate>
  <DataTemplate>
    <StackPanel>
      <Grid Height="30" >
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="2*" x:Name="NameCell"/>
          <ColumnDefinition Width="1*" x:Name="PlayersCell"/>
          <ColumnDefinition Width="1*" x:Name="FitnessCell"/>
          <ColumnDefinition Width="1*" x:Name="TechnicsCell"/>
          <ColumnDefinition Width="1*" x:Name="TacticsCell"/>
          <ColumnDefinition Width="1*" x:Name="FunCell"/>
          <ColumnDefinition Width="1*" x:Name="TypeCell"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Column="0" x:Name="Test" Content="{Binding Scene.Name}" VerticalAlignment="Center"  Width="{Binding ActualWidth, ElementName=NameColumn}" HorizontalAlignment="Center" />
        <Label Grid.Column="1" Content="{Binding Path=Scene.Players, Converter={StaticResource PlayersToTextConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <Label Grid.Column="2" Content="{Binding Path=Scene.Fitness, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <Label Grid.Column="3" Content="{Binding Path=Scene.Technics, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
        <Label Grid.Column="4" Content="{Binding Path=Scene.Tactics, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <Label Grid.Column="5" Content="{Binding Path=Scene.Fun, Converter={StaticResource IntegerToStarSxmbolConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <Viewbox Grid.Column="6" Width="24" Height="24" >
          <Path x:Name="Icon" Fill="Black" Data="{StaticResource Animations}" />
        </Viewbox>
      </Grid>
      <ListBox x:Name="RevisionsList" Visibility="Visible" ItemsSource="{Binding Revisions}" SelectedItem="{Binding SelectedRevision}" >
        <ListBox.ItemTemplate>
          <DataTEmplate>
            <TextBlock Text="{Binding Name}"></TextBlock>
          </DataTEmplate>
        </ListBox.ItemTemplate>
      </ListBox>
    </StackPanel>
    <DataTemplate.Triggers>
      <DataTrigger  Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
        <Setter TargetName="RevisionsList" Property="Visibility" Value="Visible" />
      </DataTrigger>
      <DataTrigger  Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="False">
        <Setter TargetName="RevisionsList" Property="Visibility" Value="Collapsed" />
      </DataTrigger>                       
    </DataTemplate.Triggers>
  </DataTemplate>
</ListBox.ItemTemplate> 
 
ivan_b
Topic Author
Posts: 87
Joined: 22 Jul 2015, 12:57

Re: Ignoring unsupported property 'Visibility'

22 Jan 2016, 08:08

Thank you :). I didn't know that.

Who is online

Users browsing this forum: No registered users and 1 guest