I am working on a Silverlight application that has resource files that define styles for the different types of Child Windows in the application. The <Style> contains <ControlTemplate> markup with various content. Is there a way to set one of the properties of the controls defined within the <ControlTemplate> from the Child Window’s class?
For example, imagine in the resource file I have markup like the following:
<Style x:Key="MyChildWindowStyle" TargetType="sdk:ChildWindow">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="sdk:ChildWindow">
<Grid x:Name="Root">
...
<Image Source="/Assets/image.png" />
...
</Grid>
</ContentTemplate>
</Setter>
</Style>
Now assume that I have a number of child windows that are configured to use this style. What I’d like to be able to do is from the code in those child windows be able to programmatically change the value of the image’s Source.
Is this possible?
Thanks
@zahir’s answer pointed me in the right direction, but to get it to work in Silverlight I had to do the following:
First, I added the
<BitmapImage>markup to my resource file, using theUriSourceproperty to specify the default value.Next, I referenced it in the
<ControlTemplate>like so:Then, in my code-behind class I was able to modify the
UriSourceproperty like so:Of course, the precise values for
UriSourcewould depend on how you are handling image assets, where they are located, etc.