代码之家  ›  专栏  ›  技术社区  ›  Darko

TemplateBinding a Title in custom window template WPF

  •  0
  • Darko  · 技术社区  · 14 年前

    So I'm making a custom window template for my WPF application. The trouble I'm having is that I cannot access the Window Title property inside the template.

    我试过这个:

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

    而这:

    <TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
    

    Everything that I've read indicates that either of those two should work and yet the text is never set.

    Any suggestions?

    EDIT: Presenting the entire style xaml

    <Style x:Key="RegularWindow" TargetType="{x:Type Window}">
        <Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.WindowTextBrushKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="AllowsTransparency" Value="True"/>
        <Setter Property="WindowStyle" Value="None"/>
        <Setter Property="SizeToContent" Value="WidthAndHeight"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="10" Background="{TemplateBinding Background}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <TextBlock Text="{TemplateBinding Title}" FontWeight="Bold" Grid.Row="0" />
                            <AdornerDecorator Grid.Row="1">
                                <ContentPresenter/>
                            </AdornerDecorator>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Darko    14 年前

    So it turns out that Expression Blend fails to render the window correctly. As soon as I run the code it actually works. My bad for trusting Expression Blend.