tags:

views:

171

answers:

2

Hello,

I have a ItemsControl in my XAML code. When some trigger occur i want to collapse the full itemsControl, so all the elements.

                        <ItemsControl Name="VideoViewControl"  ItemsSource="{Binding Videos}">
                            <ItemsControl.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <WrapPanel ItemHeight="120" ItemWidth="160" Name="wrapPanel1"/>
                                </ItemsPanelTemplate>
                            </ItemsControl.ItemsPanel>
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <views:VideoInMenuView />
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>

The trigger:

     <DataTrigger Value="videos" Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}, AncestorLevel=1}, Path=DataContext.VideosEnable}">
                    <Setter Property="ScrollViewer.Visibility" Value="Visible" TargetName="test1" />
                    <Setter Property="ScrollViewer.Visibility" Value="Collapsed" TargetName="test2" />
<Setter Property="WrapPanel.Visibility" Value="Collapsed" TargetName="wrapPanel1" />
                </DataTrigger>

When I add the last setter the program crashes. Without this last setter it works fine but no visibility change....

What is wrong with this code? What is the write method to collapse all the elements of a ItemsControl with a trigger?

A: 

If you want to hide the entire ItemsControl then just hide the ItemsControl itself, not its internal components (ScrollViewer and WrapPanel):

<ItemsControl.Style>
    <Style TargetType="ItemsControl">
        <Style.Triggers>
            <DataTrigger ...>
                <Setter Property="Visibility" Value="Collapsed" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</ItemsControl.Style>

That will simply set Visibility to Collapsed on the ItemsControl itself, which sounds like what you want.

Matt Hamilton
I have done that the elements are not visible anymore But they can still be found with my the WPF hittest that I use.. and that is a problemAlso set when I set the property hittestVisible of the Itemscontrol to false the elements of the itemscontrol can still be found with the hittest
Sam
Also when I debug the hittest I get the objects of the ItemControl and when i look at the properties the visibility of is visible.So when you set the property visibility of the ItemsControl to collapsed only the visibilityof the itemscontrol changed and not the visibility of the items in the itemscontrol.ThereFore I need to now how i can set the visibility of all the itemscontrol elements to colapsed when for example the visibility of the itemscontrol is set to collapsed
Sam
A: 

I found a solution:

I added this to the items of the itemscontrol:

Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=Visibility, Mode=TwoWay}"

In the WPF hittest algorithm I checked if the visibility property is collaped.

This is not a nice solution but it worked for me....

It is verry strange that if you set the visibility property of a itemscontrol to collapsed that the visibility property of the items are visible... bug?

Also strange: the hittest can find collapsed objects ...

Sam