0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

To answer your second question, Justin, you can create a style that applies a control template.

Notice that this style assigns a control template to the the Template property of a pushpin when the pushpin style is set to NumberPushpinStyle.

<Style x:Key="NumberPushpinStyle" TargetType="m:Pushpin"> <Setter Property="BorderBrush" Value="#FFF4F4F5" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid> <Ellipse Fill="Black" Height="33" Stroke="White" StrokeThickness="2" Width="33" RenderTransformOrigin="0.5,0.5"> <Ellipse.RenderTransform> <CompositeTransform TranslateX="-16" TranslateY="16" /> </Ellipse.RenderTransform> </Ellipse> <TextBlock Foreground="White" Text="{TemplateBinding Content}" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0"> <TextBlock.RenderTransform> <CompositeTransform TranslateX="-16" TranslateY="15" /> </TextBlock.RenderTransform> </TextBlock> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.