Note that there are some explanatory texts on larger screens.

plurals
  1. POModify Silverlight Resource in VisualState
    text
    copied!<p>I am wondering if there is an easy way to modify some kind of shared resource (i.e. a Brush) of a control between different VisualStates. For example, I would like to define a Brush to use as both the Background of a Border and the Fill of a different Rectangle. In a different VisualState I would like to change this background Brush in one place (the resource) and have it reflected in all elements using the resource.</p> <p>I am not sure if resources can really be referenced by Name (not Key) for the TargetName of the Storyboard in the VisualState.</p> <p>Here is a simplified example of what I am trying to do in XAML:</p> <pre><code>&lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="SilverlightApplication.MainPage" Width="200" Height="200"&gt; &lt;UserControl.Resources&gt; &lt;SolidColorBrush x:Name="Background" x:Key="Background" Color="Black" /&gt; &lt;/UserControl.Resources&gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;VisualStateManager.VisualStateGroups&gt; &lt;VisualStateGroup x:Name="MyStates"&gt; &lt;VisualState x:Name="Normal"/&gt; &lt;VisualState x:Name="Red"&gt; &lt;Storyboard&gt; &lt;ColorAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="Background" Storyboard.TargetProperty="(Color)"&gt; &lt;EasingColorKeyFrame KeyTime="00:00:00" Value="Red"/&gt; &lt;/ColorAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/VisualState&gt; &lt;/VisualStateGroup&gt; &lt;/VisualStateManager.VisualStateGroups&gt; &lt;Border Background="{StaticResource Background}" Width="100" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="Red" BorderThickness="1"/&gt; &lt;Rectangle Fill="{StaticResource Background}" Width="100" Height="100" HorizontalAlignment="Right" VerticalAlignment="Bottom"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>I have a feeling because these are StaticResources in Silverlight they are only loaded once and can not be changed. I know WPF has some concept of DynamicResources. Is there any way to achieve this type of behavior in Silverlight without having to redefine my brush in all elements?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload