【发布时间】:2011-03-08 23:25:19
【问题描述】:
所以我正在为我的 WPF 应用程序制作一个自定义窗口模板。我遇到的问题是我无法访问模板内的 Window Title 属性。
我试过这个:
<TextBlock Text="{TemplateBinding Title}" />
还有这个:
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
我读过的所有内容都表明这两者中的任何一个都应该可以工作,但文本从未设置过。
有什么建议吗?
编辑:呈现整个样式 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>
【问题讨论】:
-
可以分享一下xaml模板代码吗?