0
我試圖讓這個例子工作。我創建了一個新的WPF自定義控件庫項目,並在Generic.xaml我有以下代碼ContentControl不拾取模板,雖然DynamicResource
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCustomControlLibrary1">
<ControlTemplate x:Key="myControlTemplate1">
<TextBlock Text="This text should appear"></TextBlock>
</ControlTemplate>
<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentControl Template="{DynamicResource myControlTemplate1}"></ContentControl>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
當我使用我的控制中的應用程序,我沒有看到TextBlock
。爲什麼?
但是,如果我改變它使用模板作爲StaticResource
,它的工作原理。爲什麼?
[WPF StaticResource有效,DynamicResource不可以]的重複(http://stackoverflow.com/questions/3537107/wpf-staticresource-works-dynamicresource-doesnt) – fahadash 2014-10-29 05:44:47