-
July 28th, 2009, 12:47 AM
#1
Dynamically assign a Uri to a style
I have a WPF style as follow
<!-- Home Button Style -->
<Style x:Key="HomeButtonStyle"
TargetType="{x:Type Button}">
<Setter Property="Margin"
Value="4" />
<Setter Property="Template"
Value="{StaticResource HomeAnimation}" />
</Style>
And then the StaticResource HomeAnimation' ControTemplate defined as follow
<ControlTemplate x:Key="HomeAnimation" TargetType="{x:Type Button}">
<ControlTemplate.Resources>
xxxxxxxxxx
</ControlTemplate.Resources>
<Grid Width="Auto" Height="Auto" Background="{x:Null}" RenderTransformOrigin="0.485,0.533">
<Rectangle Fill="{StaticResource DrawBrushIconHome}" Stroke="{x:Null}" HorizontalAlignment="Left" Margin="13.166,50.218,0,0" VerticalAlignment="Top" x:Name="rectangle1" Width="20" Height="20" RenderTransformOrigin="0.5,0.5" Visibility="Hidden">
<Rectangle.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="-1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Rectangle.RenderTransform>
</Rectangle>
</Grid>
<ControlTemplate.Triggers>
xxxxxxxxx
</ControlTemplate.Triggers>
</ControlTemplate>
In the above controlTemplate there is a Rectangle Fill option with StaticResource "DrawBrushIconHome"
The DrawBrushIconHome defined as follow in the resource file
<DrawingBrush x:Key="DrawBrushIconHome" Viewbox="0,0,77.304,70" ViewboxUnits="Absolute">
<DrawingBrush.Drawing>
<ImageDrawing Rect="0,0,77.304,70">
<ImageDrawing.ImageSource>
<BitmapImage CacheOption="OnLoad" CreateOptions="IgnoreImageCache" UriSource="/Resources/home.png"/>
</ImageDrawing.ImageSource>
</ImageDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
Now my problem is how to Change the DrawBrushIconHome's UriSource images. I mean I dont want to load home.png from Resources and I would make it dynamic. So that I have to assign the image programatically from a external folder.
Can Some one please help How I can programatically set the URiSource of DrawBrushIconHome which belongs to HomeAnimation ControlTemplate and which belongs to a Button Style HomeButtonStyle.
I use C# for the development
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|