1

I have following user control:

<UserControl.Resources>

    <Style TargetType="HeaderedItemsControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="HeaderedItemsControl">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock FontFamily="Segoe Script"
                                   Text="{Binding ElementName=myHeaderedItemsControl.Header, Path=Category, Mode=OneWay}"
                                   FontWeight="Bold"
                                   HorizontalAlignment="Center"
                                   Foreground="Olive" 
                                   Margin="20"
                                   FontSize="50"
                                   TextWrapping="Wrap"
                                   Name="myText"/>
                        <ItemsPresenter Grid.Row="1" Grid.Column="1"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<Grid x:Name="LayoutRoot">        
            <TextBlock.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="-90"/>
                    <TranslateTransform/>
                </TransformGroup>
            </TextBlock.RenderTransform>
        </TextBlock>
    </StackPanel>-->
    <HeaderedItemsControl Name="myHeaderedItemsControl"  Header="Predrag">
    </HeaderedItemsControl>
</Grid>

and basically what i want is to bind Textblock text property to HeaderedItemsControl header property.

5
  • Why are you not just using a ContentPresenter with ContentSource="Header" as i showed in your other question? Commented Apr 1, 2012 at 18:35
  • because i did not managed to set appropriate style on it... Commented Apr 1, 2012 at 18:40
  • You could wrap it in a Border and set the properties there, that's usually how it's done. (Also text properties can be set via attached properties as well, e.g. TextElement.Foreground) Commented Apr 1, 2012 at 18:42
  • Why is ContentPresenter a better way? Commented Apr 1, 2012 at 18:43
  • Because it is made for this, also it does not restrict the content to plain text. Besides binding to the header it also allows you to hook up the HeaderTemplate and HeaderTemplateSelector (this happens automatically when you use ContentSource) Commented Apr 1, 2012 at 18:44

1 Answer 1

3

Why not use this:

<TextBlock Text="{TemplateBinding Header}" />

Don't know however, what the Path=Category means.

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

1 Comment

Is there a way to add other UIElement from c# code behind to HeaderedItemsControl because there is no Children property?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.