Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
C# UserControl样式-无法将样式强制转换为笔刷_C#_Wpf_Xaml_Wpf Style - Fatal编程技术网

C# UserControl样式-无法将样式强制转换为笔刷

C# UserControl样式-无法将样式强制转换为笔刷,c#,wpf,xaml,wpf-style,C#,Wpf,Xaml,Wpf Style,我正在处理WPF应用程序。我在shared.xaml中有默认样式的用户控件和主题样式(将xaml文件与不同的样式耦合) 问题是,我收到消息无法将“System.Windows.Style”类型的对象强制转换为“System.Windows.Media.Brush” 在用户控件中,共享样式如下所示: Style="{StaticResource statusBar}" 注意:当我删除这一行时,状态栏中没有错误,也没有样式(所以问题出在样式文件中) 在shared.xaml中 <Style

我正在处理WPF应用程序。我在
shared.xaml
中有默认样式的用户控件和主题样式(将xaml文件与不同的样式耦合)

问题是,我收到消息无法将“System.Windows.Style”类型的对象强制转换为“System.Windows.Media.Brush” 在用户控件中,共享样式如下所示:

Style="{StaticResource statusBar}"
注意:当我删除这一行时,状态栏中没有错误,也没有样式(所以问题出在样式文件中)

在shared.xaml中

<Style x:Key="statusBar" TargetType="{x:Type UserControl}">
    <Setter Property="Background" Value="{DynamicResource StatusBarBackgroud}"/>
    <Setter Property="FontFamily" Value="{DynamicResource FontFamilyStatusBar}"/>
    <Setter Property="FontWeight" Value="Bold"/>
    <Setter Property="Foreground" Value="{DynamicResource ForegroundStatusBar}"/>
</Style>

问题是前台(在LightTheme.xaml中,共享文件指向前台)


前景
属性为笔刷类型。当ForegroundStatusBar资源为
样式时,无法在此处分配
{DynamicResource ForegroundStatusBar}
。若前景应从基础样式继承,则在派生样式中使用BasedOn参数

<Style x:Key="statusBar" TargetType="{x:Type UserControl}" 
       BasedOn="{StaticResource ForegroundStatusBar}">
    <Setter Property="Background" Value="{DynamicResource StatusBarBackgroud}"/>
    <Setter Property="FontFamily" Value="{DynamicResource FontFamilyStatusBar}"/>
    <Setter Property="FontWeight" Value="Bold"/>
    <!--Foreground setter removed-->
</Style>

试试这个:

<Style x:Key="ForegroundStatusBar"
   TargetType="{x:Type UserControl}">
   <Setter Property="Foreground" Value="LightBlue"></Setter>
</Style>

<Style x:Key="ForegroundStatusBar"
   TargetType="{x:Type UserControl}">
   <Setter Property="Foreground" Value="LightBlue"></Setter>
</Style>