简体   繁体   English

将MahApps.Metro主题和重音应用于其他控件或矩形

[英]Apply MahApps.Metro theme and accent to other controls or rectangles

I'm trying to put a status bar on the bottom of my window that uses the same color scheme as the title bar. 我正在尝试在窗口底部放置一个状态栏,使用与标题栏相同的颜色方案。 I know the piece I'm missing is style inheritance and/or template setting, but I've been reading for hours and I can't figure it out. 我知道我缺少的是样式继承和/或模板设置,但我已经阅读了几个小时,我无法弄明白。

Here's how my window currently looks: 这是我的窗口当前的样子:

运行时的窗口组合

Here's how it looks in the designer: 以下是它在设计师中的表现:

设计师的窗口组成

What I want: 我想要的是:

A status bar at the bottom of the window that mirrors the style of the titlebar. 窗口底部的状态栏,用于反映标题栏的样式。 I recognize that my current implementation is probably less than great, so I'm also open to changing my statusbar defintiion as seen below. 我认识到我目前的实现可能不太好,所以我也愿意改变我的状态栏定义,如下所示。 I tried to use an actual statusbar, but it wouldn't behave the way I wanted (the textboxes wouldn't fill the empty space, so the command line input textbox was very hard to click - maybe I was just doing something wrong). 我试图使用一个实际的状态栏,但它不会按照我想要的方式运行(文本框不会填充空白区域,因此命令行输入文本框很难点击 - 也许我只是做错了什么)。 I'm assuming I can also apply the style to a rectangle just like anything else, right? 我假设我也可以像其他任何东西一样将样式应用于矩形,对吧? I'm missing a critical component with the style property and probably the user of a template or a staticresource, but I'm totally lost. 我错过了一个带有style属性的关键组件,可能是模板或静态资源的用户,但我完全迷失了。

Here's my current solution (a label and two textboxes for status updates and a cmdline): 这是我目前的解决方案(标签和两个用于状态更新和cmdline的文本框):

<Grid Grid.Row="1">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="0.5*"/>
        <ColumnDefinition Width="0.5*"/>
    </Grid.ColumnDefinitions>
    <Label Grid.Column="0"/>
    <Grid  Grid.Column="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <TextBox Grid.Row="0" Grid.Column="0"/>
        <TextBox Grid.Row="0" Grid.Column="1"/>
    </Grid>
</Grid>

I solved this by using the AccentColorBrush resource in my status bar grid. 我通过在状态栏网格中使用AccentColorBrush资源解决了这个问题。

<Grid Grid.Row="1" Background="{DynamicResource AccentColorBrush}">

I found it by inspecting many XAML files in MahApps.Metro on GitHub. 我通过检查GitHub上的MahApps.Metro中的许多XAML文件找到了它。 This may seem obvious to some people, but for someone who is trying to learn XAML/WPF/MVVM, this wasn't straight forward. 对于某些人来说这似乎是显而易见的,但对于那些试图学习XAML / WPF / MVVM的人来说,这并不是直截了当的。 I hope this helps someone as I struggled with it for quite a while. 我希望这可以帮助某些人,因为我已经挣扎了很长一段时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM