我有我写这个控件模板:为什么我不能在控件模板中使用模板绑定?
<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