I want to be able to "change" my listview into another control. I was thinking having the control's visibility set to hidden and when a button is clicked, change the visibility. Do I have to do this programatically? Or can I use a trigger?
A:
You can use a Storyboard and/or trigger to do this, no problem. Just animate the Visibility properties on the elements you want to change.
Muad'Dib
2010-01-26 01:33:54
A:
To add to Muad'Dib's answer, another way you can do it is to stack the controls on top of each other, then fade the Opacity back and forth in the trigger. You can also do this with VSM (Create a ListboxVisible state and a ListboxHidden state, or whatever name makes more sense semantically)
Paul Betts
2010-01-26 01:54:10
+1
A:
You can use a trigger to change the Template property of a ContentControl, which will wrap the control you want to be "changeable". Check this:
Add this to Resources:
<ControlTemplate x:Key="BoxTemplate">
<TextBox Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type ContentControl}},Path=Content}" />
</ControlTemplate>
<ControlTemplate x:Key="BlockTemplate" >
<TextBlock Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor,
AncestorType={x:Type ContentControl}},Path=Content}" />
</ControlTemplate>
<ControlTemplate x:Key="TestTemplate" >
<StackPanel>
<CheckBox x:Name="Switch" />
<ContentControl x:Name="MyContent" Template="{StaticResource BoxTemplate}"
Content="Data is unique!" />
</StackPanel>
<ControlTemplate.Triggers>
<Trigger SourceName="Switch" Property="IsChecked" Value="True">
<Setter TargetName="MyContent"
Property="Template"
Value="{StaticResource BlockTemplate}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
Test it using another ContentControl:
<ContentControl Template="{StaticResource TestTemplate}"/>
I'm sure it could be optimized, but should put you on the track.
Natxo
2010-01-26 13:12:58