问题描述:

I need to have a custom UI element that can be changed, such as the colour and text used in the application but as a resource - in WPF I can use a DynamicResource to assign brushes, strings etc, however I need to implement this in Silverlight 3 - how can I do this as a StaticResource will not do, and as another question I have a resource which is made of other UI-Elements like Rectangles. See example from my existing ResourceDictionary:

 <VisualBrush x:Key="Device" Stretch="Uniform">

<VisualBrush.Visual>

<Canvas Width="20" Height="36">

<Rectangle Height="36" Width="20" Fill="{DynamicResource ZuneColour}" Canvas.Left="0" Canvas.Top="0" RadiusX="1" RadiusY="1">

<Rectangle.BitmapEffect>

<OuterGlowBitmapEffect GlowColor="Black" GlowSize="2" />

</Rectangle.BitmapEffect>

</Rectangle>

<Rectangle Fill="{DynamicResource ZuneScreen}" Canvas.Left="1" Canvas.Top="1" Height="24" Stroke="#191616" Width="18"/>

<Rectangle Canvas.Left="5.5" Canvas.Top="25" Height="9" Width="9" RadiusX="3" RadiusY="3" Fill="{DynamicResource ZunePad}" Stroke="{DynamicResource ZunePadOuter}"/>

</Canvas>

</VisualBrush.Visual>

</VisualBrush>

I have also had an issue with replicating the OuterGlowEffect, but at least this can be done with a compiled DirectX effect so can leave this out if needed.


I think Data Bindings will be a good solution to dynamic content as can create a Class which

stores the visual data I need and this can be a One-way binding to update the UI - hopefully this may be useful to others with the same issue.

Still need to replace VisualBrush functionality with something that will work in Silverlight for the given example.

相关阅读:
Top