gpt4 book ai didi

c# - 如何以编程方式分配样式

转载 作者:太空宇宙 更新时间:2023-11-03 23:08:03 25 4
gpt4 key购买 nike

<分区>

我正在尝试将我的一种 xaml 样式设置为我页面中的框架。它是用代码创建的,并动态分配给布局。

所以我希望我必须动态设置样式?因为框架在 xaml 中不存在。

我想不通的是如何分配自定义模板。或者更好的是,以全局方式处理适合特定类别的任何帧。标签或类型等

下面是我正在尝试测试的模板。但它不起作用。假设代码丢失,所以开始检查代码隐藏样式设置,但到目前为止没有运气。

App.xaml

<!-- http://paulstovell.com/blog/wpf-navigation -->
<ControlTemplate TargetType="Frame" x:Key="frame" >
<DockPanel Margin="7">
<StackPanel
Margin="7"
Orientation="Horizontal"
DockPanel.Dock="Top"
>
<Button
Content="Avast! Go back!"
Command="{x:Static NavigationCommands.BrowseBack}"
IsEnabled="{TemplateBinding CanGoBack}"
/>
<Button
Content="Forward you dogs!"
Command="{x:Static NavigationCommands.BrowseForward}"
IsEnabled="{TemplateBinding CanGoForward}"
/>
</StackPanel>

<Border
BorderBrush="Green"
Margin="7"
BorderThickness="7"
Padding="7"
CornerRadius="7"
Background="White"
>
<ContentPresenter />
</Border>
</DockPanel>
</ControlTemplate>

MyWindow.xaml.cs

 Frame newFrame = new Frame();
newFrame.Content = content;

newFrame.Template = ControlTemplate ...?

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