如何使用样式(混音)更改 MahApps.Metro 对话框内容 [英] How to change MahApps.Metro dialog content using styles (remix)
问题描述
这个问题的一个版本已经被问到这里.
sA version of this question has already been asked here.
我认为答案清晰简洁,但我不太明白,而且我认为我不应该开始大量的评论试图弄明白(正如张贴出来的那样是正确的礼仪这里一>)
I think the answer is clear and concise, but I don't quite understand it, and I didn't think I should start a massive chain of comments trying to figure it out(as posted out is proper etiquette here)
我想在我的 MahApps.Metro 对话框中添加一个额外的按钮.我需要一个浏览按钮,以便用户可以输入目录.这个答案显示了如何做到这一点,但我不太明白,因为我对 C# 和 WPF 还很陌生.
I'd like to add an extra button in my MahApps.Metro Dialog. I need a Browse button so that a user can input a directory. This answer shows how to do that, but I don't quite understand since I'm fairly new to C# and WPF.
我不明白的是我应该在我的 xaml 文件中的哪个位置放置 部分.
What I don't understand is exactly where in my xaml file I should be placing the <Style></Style>
section.
如果我猜测它可以在我的 <Grid></Grid>
之外的任何地方使用是正确的,那么我会收到我不明白的错误.
If I'm correct in guessing that it can go anywhere outside of my <Grid></Grid>
then I'm getting errors that I don't understand.
我当前的代码 .xaml 文件.
My current code .xaml file.
<Controls:MetroWindow x:Class="testApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"
Title="testApp" Height="auto" Width="auto"
EnableDWMDropShadow="True"
ResizeMode="CanResizeWithGrip"
WindowTransitionsEnabled="False"
WindowStartupLocation="CenterScreen" Loaded="OnLoaded">
<Grid>
<!--some content -->
</Grid>
</Controls:MetroWindow>
如果我在 Grid 部分上方插入 Style 部分,我会收到一个错误 未定义命名空间Dialog"
If I insert the Style section above the Grid section I get an error The namespace "Dialog" is not defined
我认为 xmlns xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"
应该添加对话框吗?
I thought the xmlns xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"
should have added the Dialogs?
一旦我能够获得样式集,我想我只需添加上一个答案中的以下代码(使用我想要的按钮).
Once I'm able to get the style set, I imagine I just add the below code from the previous answer (with the buttons I'd like).
<Dialogs:CustomDialog x:Key="CustomDialogTest"
Style="{StaticResource NewCustomDialogStyle}"
Title="This dialog allows arbitrary content. It will close in 5 seconds."
x:Name="CustomTestDialog">
<StackPanel>
<TextBlock Height="30"
Text="This dialog allows arbitrary content. You have to close it yourself by clicking the close button below."
TextWrapping="Wrap"
Foreground="{DynamicResource AccentColorBrush}" />
<Button Content="Close Me!" />
</StackPanel>
</Dialogs:CustomDialog>
我不明白什么?提前致谢
What am I not understanding? Thanks in advance
注意
我没有添加我的 .cs 代码 b/c 我在实际显示标准异步对话框时没有问题.
I didn't add my .cs code b/c I'm having no problem actually getting the standard async dialog showing.
推荐答案
原来我试图正确地做到这一点,但我遇到了一个解释的问题 这里(Wouter 的回答).
It turns out I was trying to do this correctly, but I was running into a problem explained here (The answer by Wouter).
原来我必须指定程序集,所以
It turns out I had to specify the assembly, so
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs"
应该
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
这消除了我在样式中的错误.
That cleared up my errors in the Style.
所以最后,我必须设置的样式是:
So in the end, what I had to set the style was:
<Control.Resources>
<Style TargetType="{x:Type Dialogs:BaseMetroDialog}">
</Style>
</Control.Resources>
与
xmlns:Dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
在顶部.
这篇关于如何使用样式(混音)更改 MahApps.Metro 对话框内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!