Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF C#在新窗口中更新资源_C#_Wpf_Dynamicresource - Fatal编程技术网

WPF C#在新窗口中更新资源

WPF C#在新窗口中更新资源,c#,wpf,dynamicresource,C#,Wpf,Dynamicresource,我在更新新窗口中的颜色时遇到问题。 资源位于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;ass

我在更新新窗口中的颜色时遇到问题。 资源位于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"/>
我有时在应用程序中使用progressbar加载新窗口时生成

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并更改值时,应用程序中的每种颜色都会更改,但此窗口仍为默认颜色。
有人能帮忙吗?谢谢

您是说当窗口仍然打开时,您更改了颜色的值,(窗口在屏幕上打开)颜色在资源中更改,而不是在窗口上更改?如果是这样,那么如果要动态更改控件的重新排序,那么您需要重新渲染控件(我可能错了)。因为我不相信对底层样式/资源的更新会触发更新。但是,您可以绑定颜色,而不是使用
DynamicResource
,后者可以实现Notify属性no,I更改值,然后创建并显示窗口。
<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>