I have a Silverlight controls assembly, called "MySilverlightControls". Several folders down into that assembly I have a class which extends a grid column from a third party vendor, let's call it "MyImageColumn.cs".
I have also created a resource dictionary called Generic.xaml
, this is situated in the Themes
folder of the assembly. In that resource dictionary i have defined a ControlTemplate called MyImageColumnTemplate:
<ControlTemplate x:Name="MyImageColumnTemplate" >
<Grid Margin="8,8,4,4" MaxHeight="32" MaxWidth="32">
<Grid.Resources>
<localGrid:StatusColumnImageConverter x:Key="ImageContentConverter"/>
</Grid.Resources>
<Border Margin="5,5,0,0" Background="Black" Opacity="0.15" CornerRadius="5" />
<Border Background="#FF6E6E6E" CornerRadius="4,4,4,4" Padding="4" Margin="0,0,5,5">
<Border Background="White" CornerRadius="2,2,2,2" Padding="3">
<Image Source="{Binding EditValue, Converter={StaticResource ImageContentConverter}}" Stretch="Uniform"/>
</Border>
</Border>
</Grid>
</ControlTemplate>
My question is: from MyImageColumn, how can I programmatically reference/load this control template so I can assign it to a property on the column? I would expect to be using a syntax similar to this:
ControlTemplate ct = (ControlTemplate)Application.Current.Resources["MyImageColumnTemplate"];
but this always returns null. When I load the assembly up in Reflector, I see that the Generic.xaml
file is there, the name of the resource is MySilverlightControls.g.resources
, and the path within that is themes/generic.xaml
.
How exactly can I get to the individual items in this resource dictionary?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…