如何将ModernUI 背景颜色(深色/浅色)应用于UserControl?我成功检索并应用了重音颜色,但我无法弄清楚如何应用深色/浅色背景色。默认情况下,我的UserControl的背景是透明的。
以下是我如何应用重音颜色(这可行):
<UserControl x:Class="GenkaiModern.Pages.DetailView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:GenkaiModern.Pages"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="399.533" d:DesignWidth="751.402" Width="720" Height="350" Background="{DynamicResource Accent}" >
</UserControl>
这可能很简单,但我无法弄清楚如何使用这些资源属性。
现在这里的主窗口有一个适用于它的背景主题(我甚至不知道如何)
<mui:ModernWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="GenkaiModern.MainWindow"
Title="Genkai Client" IsTitleVisible="True"
LogoData="F1 M 24.9015,43.0378L 25.0963,43.4298C 26.1685,49.5853 31.5377,54.2651 38,54.2651C 44.4623,54.2651 49.8315,49.5854 50.9037,43.4299L 51.0985,43.0379C 51.0985,40.7643 52.6921,39.2955 54.9656,39.2955C 56.9428,39.2955 58.1863,41.1792 58.5833,43.0379C 57.6384,52.7654 47.9756,61.75 38,61.75C 28.0244,61.75 18.3616,52.7654 17.4167,43.0378C 17.8137,41.1792 19.0572,39.2954 21.0344,39.2954C 23.3079,39.2954 24.9015,40.7643 24.9015,43.0378 Z M 26.7727,20.5833C 29.8731,20.5833 32.3864,23.0966 32.3864,26.197C 32.3864,29.2973 29.8731,31.8106 26.7727,31.8106C 23.6724,31.8106 21.1591,29.2973 21.1591,26.197C 21.1591,23.0966 23.6724,20.5833 26.7727,20.5833 Z M 49.2273,20.5833C 52.3276,20.5833 54.8409,23.0966 54.8409,26.197C 54.8409,29.2973 52.3276,31.8106 49.2273,31.8106C 46.127,31.8106 43.6136,29.2973 43.6136,26.197C 43.6136,23.0966 46.127,20.5833 49.2273,20.5833 Z"
ContentSource="/Pages/Home.xaml" d:DesignWidth="1070.985" d:DesignHeight="664.851">
<mui:ModernWindow.MenuLinkGroups>
<mui:LinkGroup DisplayName="Administration" GroupKey="Administration">
<mui:LinkGroup.Links>
<mui:Link DisplayName="Machine" Source="/Pages/NewComputerView.xaml" />
<mui:Link DisplayName="Ecrans" Source="/Pages/Home.xaml"/>
<mui:Link DisplayName="Imprimantes" Source="/Pages/Home.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
<mui:LinkGroup DisplayName="settings" GroupKey="settings">
<mui:LinkGroup.Links>
<mui:Link DisplayName="Application" Source="/Pages/SettingsPage.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
<mui:LinkGroup DisplayName="Login" GroupKey="Login">
<mui:LinkGroup.Links>
<mui:Link DisplayName="Login" Source="/Pages/AutentificationView.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>
<mui:ModernWindow.TitleLinks>
<mui:Link DisplayName="Administration" Source="/Pages/NewComputerView.xaml" />
<mui:Link DisplayName="Login" Source="/Pages/AutentificationView.xaml" />
<mui:Link DisplayName="settings" Source="/Pages/SettingsPage.xaml" />
<mui:Link DisplayName="help" Source="https://github.com/firstfloorsoftware/mui" />
</mui:ModernWindow.TitleLinks>
</mui:ModernWindow>
根据我的理解,因为在我的usercontrole字体中采用了modernui的字体主题,如果我的背景不是透明的,那么它的粗糙颜色就会变暗,这会让它变得混乱。
答案 0 :(得分:1)
如果您想动态更改UI的颜色,则使用DynamicResource
是合适的。例如,SolidColorBrush
中的deckare App.xaml
:
<Application.Resources>
<SolidColorBrush x:Key="DynamicColor" />
</Application.Resources>
在您的控制中,您应该通过DynamicResource
:
<UserControl x:Class=""
<!--The code is omitted for the brevity-->
d:DesignHeight="600" d:DesignWidth="800">
<Grid Name="mainGrid" Background="{DynamicResource DynamicColor}">
</Grid>
</UserControl>
然后改变Resource
你应该:
Application.Current.Resources["YourResource"] = YourNewValue;
让我举例说明如何改变价值:
private void Window_ContentRendered(object sender, EventArgs e)
{
SolidColorBrush YourBrush = (Brush)(new BrushConverter().ConvertFrom("#455A65"));;
// Set the value
Application.Current.Resources["DynamicColor"] = YourBrush;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SolidColorBrush YourBrush = Brushes.Orange;
// Set the value
Application.Current.Resources["DynamicColor"] = YourBrush;
}
DynamicResources
用于更改。在哪里改变 - 这是开发人员的愿望。
答案 1 :(得分:0)
我挖掘了FirstFloor示例应用程序,发现有一些DynamicResource键用于主题格式化。我能够通过以下方式获得我主题的窗口背景颜色:
command brew services list
然后在某个地方使用它,比如......
<SolidColorBrush x:Key="BackgroundBrush" Color="{DynamicResource WindowBackgroundColor}" />
还有其他DynamicResource键,包括
<DataGrid Background="{StaticResource BackgroundBrush}" />
我发现这些浏览来自MUI-master源代码。 有关更多信息,请打开mui-master.sln并导航到项目FirstFloor.ModernUI(类库)/Themes/ModernWindow.xaml和/Themes/ModernDialog.xaml