我在XAML里面制定好了一个控件模板 : 是定义在Resources里面的对吧?
例如你是这样定义的:
<Window.Resources>
<ControlTemplate x:Key="template">
<Border Background="Black" Opacity="0.6" BorderThickness="2" BorderBrush="Red">
<TextBlock Text="My Button"/>
</Border>
</ControlTemplate>
</Window.Resources>
<Grid>
<Button x:Name="myButton"/>
</Grid>
你可以在后台通过findResource方法找到你的resource然后赋值。
ControlTemplate template = this.FindResource("template") as ControlTemplate;
if (template != null)
myButton.Template = template;
Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
