我有我寫這個控件模板:爲什麼我不能在控件模板中使用模板綁定?
<Style TargetType="{x:Type controls:InfoBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:InfoBar}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<StackPanel>
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="{TemplateBinding FontFamily}" />
<Setter Property="FontSize" Value="{TemplateBinding FontSize}" />
<Setter Property="Foreground" Value="{TemplateBinding Foreground}" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ItemsControl Grid.Column="0" ItemsSource="{TemplateBinding LeftInfoBarTextBlockCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ItemsControl Grid.Column="1" ItemsSource="{TemplateBinding MiddleInfoBarTextBlockCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<ItemsControl Grid.Column="2" ItemsSource="{TemplateBinding RightInfoBarTextBlockCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
XAML的這部分拋出member is not valid because it does not contain a valid type name.
例外上的FontFamily,字號和前景模板綁定。
<Grid.Resources>
如果我把它改成這樣:
<Grid.Resources>
將建成,但是當我調試它,我得到這個XmlParseExeption
:
Set property 'System.Windows.Setter.Value' threw an exception.
如果我改變controls:InfoBar
到Control
,其信息欄從繼承,我得到相同的異常。
我在做什麼錯?
有沒有什麼辦法可以完成我正在嘗試的那種風格,沒有TemplateBinding? – Justin 2010-04-26 19:56:43