猿问

如何在 Prism WPF 中将类库 ResourceDictionary xaml

我有一个名为 CommonStyles 的类库。CommonStyles 类库具有 ButtonStyle。我想将 ButtonStyle 引用到 Shell 窗口的按钮。我已经提到了Link。但是我没有通过这个链接得到任何明确的答案。请任何人帮我解决这个问题。


按钮样式.xaml


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

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


    <Style x:Key="FocusVisual">

        <Setter Property="Control.Template">

            <Setter.Value>

                <ControlTemplate>

                    <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>

                </ControlTemplate>

            </Setter.Value>

        </Setter>

    </Style>

    <SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/>

    <SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>

    <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/>

    <SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/>

    <SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/>

    <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>

    <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>

    <SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/>

    <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>

    <Style x:Key="ButtonStyle" TargetType="{x:Type Button}">

        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>

        <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>

        <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>

        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>

        <Setter Property="BorderThickness" Value="1"/>


凤凰求蛊
浏览 160回答 1
1回答

Qyouu

将资源字典合并到您的窗口中:<Window x:Class="ThemesTesting.ShellWindow"&nbsp; &nbsp; &nbsp; &nbsp; xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&nbsp; &nbsp; &nbsp; &nbsp; xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&nbsp; &nbsp; &nbsp; &nbsp; xmlns:d="http://schemas.microsoft.com/expression/blend/2008"&nbsp; &nbsp; &nbsp; &nbsp; xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; mc:Ignorable="d"&nbsp; &nbsp; &nbsp; &nbsp; Height="450" Width="800">&nbsp; &nbsp; <Window.Resources>&nbsp; &nbsp; &nbsp; &nbsp; <ResourceDictionary>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ResourceDictionary.MergedDictionaries>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ResourceDictionary Source="pack://application:,,,/CommonStyles;component/ButtonStyle.xaml"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ResourceDictionary.MergedDictionaries>&nbsp; &nbsp; &nbsp; &nbsp; </ResourceDictionary>&nbsp; &nbsp; </Window.Resources>&nbsp; &nbsp; <Grid>&nbsp; &nbsp; &nbsp; &nbsp; <Button Height="50" Width="100" Content="Click Me" Style="{StaticResource ButtonStyle}"></Button>&nbsp; &nbsp; </Grid></Window>如果ResourceDictionary定义的程序集称为“CommonStyles”,并且它ResourceDictionary本身被命名为“ButtonStyle.xaml”并且位于CommonStyles项目的根目录中,则这应该有效。您还需要CommonStyles.dll从ShellWindow定义的项目中添加一个引用。
随时随地看视频慕课网APP
我要回答