views:

61

answers:

1

I have this control template that I am writing:

<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>

This section of xaml is throwing member is not valid because it does not contain a valid type name. exceptions for the template bindings on FontFamily, FontSize and Foreground.

<Grid.Resources>

If I change it to this:

 <Grid.Resources>

It will build, but when I debug it, I get this XmlParseExeption:

Set property 'System.Windows.Setter.Value' threw an exception.

If I change controls:InfoBar to Control, which InfoBar inherits from, I get the same exception.

What am I doing wrong?

+1  A: 

The problem is in this:

<Style TargetType="{x:Type TextBlock}">         
   <Setter Property="FontFamily" Value="{TemplateBinding FontFamily}" />         
   <Setter Property="FontSize" Value="{TemplateBinding FontSize}" />         
   <Setter Property="Foreground" Value="{TemplateBinding Foreground}" />         
</Style>

You can use TemplateBinding only inside a control template. and here you using it inside a style.

rantri
Is there any way I can accomplish what I was trying to do in that style, without the TemplateBinding?
Justin