我在新窗口中更新颜色时遇到问题。 资源在App.xml中
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="EOS_Toolkit.App"
StartupUri="MainWindow.xaml">
<Application.Resources>
<SolidColorBrush x:Key="EOS_RED" Color="#FF619C1A"/>
<SolidColorBrush x:Key="EOS_GRAY" Color="#FF666366"/>
<SolidColorBrush x:Key="NORMAL_TEXT" Color="#FF000000"/>
<SolidColorBrush x:Key="DESC_TEXT" Color="#FF7C7C7C"/>
<SolidColorBrush x:Key="MAIN_BACKGROUND" Color="#FFFFFFFF"/>
我按类加载模板并设置它
def = templates[name];
if (def.eos_red != null) { Application.Current.MainWindow.Resources["EOS_RED"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(def.eos_red)); }
if (def.eos_gray != null) { Application.Current.MainWindow.Resources["EOS_GRAY"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(def.eos_gray)); }
if (def.normal_text != null) { Application.Current.MainWindow.Resources["NORMAL_TEXT"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(def.normal_text)); }
if (def.desc_text != null) { Application.Current.MainWindow.Resources["DESC_TEXT"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(def.desc_text)); }
if (def.main_background != null) { Application.Current.MainWindow.Resources["MAIN_BACKGROUND"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(def.main_background)); }
我在使用进度条加载新窗口时有时会在应用程序中进行。
Load loading = new Load(); // okno s progressbarem
loading.Owner = this;
loading.Closed += loading_done;
this.IsEnabled = false;
loading.Show();
_Plugins[Convert.ToString(sender.lab_name.Text)].Load(loading.prg_load);
loading.Hide();
this.IsEnabled = true;
这里是新窗口的xaml
<Window x:Class="EOS_Toolkit.Load"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Načítaní..." Height="81" Width="300" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" WindowStyle="None" AllowsTransparency="True" Topmost="True" Background="{DynamicResource MAIN_BACKGROUND}">
<Window.Effect>
<DropShadowEffect/>
</Window.Effect>
<Border BorderBrush="{DynamicResource EOS_RED}" BorderThickness="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Rectangle Fill="{DynamicResource EOS_RED}" Margin="0" Grid.Row="0" Stroke="{DynamicResource EOS_RED}" Height="20" VerticalAlignment="Top"/>
<Label Content="Načítaní..." Margin="0" Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Center" FontFamily="Arial" FontSize="24" Foreground="{DynamicResource NORMAL_TEXT}" />
<ProgressBar x:Name="prg_load" Height="10" Margin="5,0" Grid.Row="2" VerticalAlignment="Top" Foreground="{DynamicResource EOS_RED}" Background="#33000000" BorderBrush="{x:Null}"/>
</Grid>
</Border>
</Window>
问题是当我加载temlate并更改值时,应用程序中的每种颜色都会更改,但此窗口仍为默认颜色。 有人可以帮忙吗?感谢