Reputation: 17045
In WPF custom control I used to implement appearence changing of a custom control based on another property of this custom control with the help of Triggers mechanism, for example when my custom control changes its property AStatus
to value Available
its background color changes to Green
:
<Trigger Property="AStatus" Value="Available">
<Setter TargetName="PART1" Property="Background" Value="Green"/>
<Setter TargetName="PART_Backgr" Property="Background" Value="Green"/>
</Trigger>
But Silverlight lacks of Triggers functionality. And for changing appearence of custom controls in Silverlight the VisualStateManager should be used. But I cannot find the way this condition can be implemented with the help of the VisualStateManager.
How is it possible to implement changing a style of Silverlight custom control when another property of this custom control changes?
Upvotes: 0
Views: 657
Reputation: 59763
You have two reasonable options:
1) In the backing code for the property "AStatus", which you may want to make a dependency property, switch to a new VisualState using the VisualStateManager. There is not a fully XAML solution like in WPF when using this technique though. Create a VisualState that represents the style/setters that you want to use (much like a trigger).
Here is an example from my blog.
2) If you use Blend 4, you can use the DataStateBehavior to perform the work that could have been done manually (as in option #1). You can download the Blend 4 SDK to make these types of changes using XAML (or a visual designer).
I usually go with #1 though if writing a custom control to minimize dependencies on other assemblies.
Upvotes: 1