WPF用户控件XAML绑定

时间:2012-04-01 18:28:18

标签: .net wpf xaml binding wpf-controls

我有以下用户控制:

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

基本上我想要的是将Textblock文本属性绑定到HeaderedItemsControl标题属性。

1 个答案:

答案 0 :(得分:3)

为什么不使用它:

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

然而,不知道Path=Category意味着什么。