I have to apply the same data trigger on multiple items. Data trigger is
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=someButton, Path=IsChecked}" Value="False">
<Setter Property="UIElement.Visibility" Value="Collapsed" />
</DataTrigger>
</Style.Triggers>
</Style>
The issue is that I have to copy it for every label, text field, check box, button etc that I want to collapse/show, and this is one button, and the end layout is pretty complicated, with many buttons, so, is there a better way (something like class etc?)
Also the trigger is working perfectly with items such as buttons etc, but it is not working for any panels, dock panel, grid, canvas etc. Any ideas?
Using .NET 4.0, Visual Studio 2010 express.
I think the first question is why this is a
DataTriggerin the first place. Using aBooleanToVisibilityConverter, you can bindVisibilitydirectly to theIsCheckedproperty.Beyond that, you can clean things up substantially by making
IsCheckeda two-way binding to a property on the viewmodel, likeAreControlsVisible. Then all the other controls can simply haveVisibility="{Binding AreControlsVisible…Another option is to make that style a resource, and apply it to all of the appropriate elements.