gpt4 book ai didi

.net - 错误: Cannot find the Style Property 'Template' on the type 'System.Windows.Controls.Primitives.Popup'

转载 作者:行者123 更新时间:2023-12-01 22:37:44 26 4
gpt4 key购买 nike

我必须为弹出窗口创建样式。我正在使用 WPF 和 .NET Framework 4。

我写的风格:

<Style x:Key="PopupBox" TargetType="{x:Type Popup}">   
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Popup}">
<Grid>
<Border BorderBrush="Blue" Background="#FFFFFFFF">
<Grid>
<Border Background="AliceBlue"/>
<ContentPresenter ContentSource="Header" />
<ContentPresenter/>
<Border BorderBrush="#FFFFFFFF" Background="#FFBFDBFF"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

我从这段代码中删除了一些元素,例如网格行和列定义,因为它们并不重要。

看来我不能使用<Setter Property="Template">因为Popup控件没有这个属性。我该如何解决这个问题?

非常感谢这里的任何帮助!

最佳答案

由于 Popup 没有任何模板,只有内容的 Child 属性,因此您可以使用其他控件(例如 ContentControl)来设置样式和模板:

<Style x:Key="PopupContentStyle" TargetType="ContentControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Border BorderBrush="Blue" Background="#FFFFFFFF">
<Grid>
<Border Background="AliceBlue"/>
<ContentPresenter/>
<Border BorderBrush="#FFFFFFFF" Background="#FFBFDBFF"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

然后将其放置在每个需要它的Popup中:

<Popup>
<ContentControl Style="{StaticResource PopupContentStyle}">
<!-- Some content here -->
</ContentControl>
</Popup>

关于.net - 错误: Cannot find the Style Property 'Template' on the type 'System.Windows.Controls.Primitives.Popup' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8383253/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com