Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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/0/svn/5.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# WPF和外部CSS文件_C#_.net_Css_Wpf_Xaml - Fatal编程技术网

C# WPF和外部CSS文件

C# WPF和外部CSS文件,c#,.net,css,wpf,xaml,C#,.net,Css,Wpf,Xaml,是否可以将样式定义存储在一个文件(XXXXX.css)中,然后在XAML文件中使用此文件?它不是css,但您可以在单独的文件中创建一个资源字典,如下所示: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style

是否可以将样式定义存储在一个文件(XXXXX.css)中,然后在XAML文件中使用此文件?

它不是css,但您可以在单独的文件中创建一个资源字典,如下所示:

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="MyStyledButton" TargetType="Button">
        .
        Put the details of your style here, just like you would for a normal style.
        .
    </Style>

</ResourceDictionary>

.
把你的风格的细节放在这里,就像你会为一个正常的风格。
.
然后,您可以通过设置类上的资源将该资源字典导入到其他XAML文件中,例如,如果您有一个窗口类,您可以执行以下操作:

<Window.Resources>
    <ResourceDictionary Source="MyStylesFile.xaml" />
</Window.Resources>

现在,该样式对窗口中的任何控件生效,就像您直接在窗口资源中指定了样式一样