Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.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# 类库中的可移植XAML样式_C#_Wpf_Visual Studio_Xaml_Portability - Fatal编程技术网

C# 类库中的可移植XAML样式

C# 类库中的可移植XAML样式,c#,wpf,visual-studio,xaml,portability,C#,Wpf,Visual Studio,Xaml,Portability,因此,我有一个应用程序,其样式直接放在App.xaml文件中,如下所示: 任何帮助都将不胜感激。谢谢 你读到的是正确的 您需要的是在共享程序集中创建一个具有给定名称的普通ResourceDictionary 然后,在App.xaml中,您可以将此ResourceDictionary作为合并词典包含在内,因此您的整个应用程序都可以访问所有共享词典资源 步骤: 创建另一个项目WPF控件库项目与用户或自定义无关 在新项目中,右键单击->添加->资源字典 粘贴您的样式,使其看起来如下所示: 字典1.x

因此,我有一个应用程序,其样式直接放在App.xaml文件中,如下所示:


任何帮助都将不胜感激。谢谢

你读到的是正确的

您需要的是在共享程序集中创建一个具有给定名称的普通ResourceDictionary

然后,在App.xaml中,您可以将此ResourceDictionary作为合并词典包含在内,因此您的整个应用程序都可以访问所有共享词典资源

步骤:

创建另一个项目WPF控件库项目与用户或自定义无关 在新项目中,右键单击->添加->资源字典 粘贴您的样式,使其看起来如下所示: 字典1.xaml


你读的是正确的

您需要的是在共享程序集中创建一个具有给定名称的普通ResourceDictionary

然后,在App.xaml中,您可以将此ResourceDictionary作为合并词典包含在内,因此您的整个应用程序都可以访问所有共享词典资源

步骤:

创建另一个项目WPF控件库项目与用户或自定义无关 在新项目中,右键单击->添加->资源字典 粘贴您的样式,使其看起来如下所示: 字典1.xaml


非常感谢。一旦有机会实施,我会立即回复。附言:我只有15岁才能投票。谢谢!一旦有机会实施,我会立即回复。附言:我只有15岁才能投票。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="SpecialButtonStyle" TargetType="Button">
        <Setter Property="Content" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}" />
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}" />
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Block.Foreground" Value="White" />
        <Setter Property="TextBlock.Foreground" Value="White" />
        <Setter Property="TextElement.Foreground" Value="White" />
        <Setter Property="FontWeight" Value="Bold" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="False">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Border Background="{TemplateBinding Background}" Padding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=BorderThickness}">
                                <Border Background="{TemplateBinding BorderBrush}">
                                    <ContentControl Foreground="White">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                    </ContentControl>
                                </Border>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>
<Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 StartupUri="NestedXamlObjects.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/WpfControlLibrary1;component/Dictionary1.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>