繁体   English   中英

不同装配中的WPF替代样式

[英]WPF Override style in different assembly

我正在尝试制作一个可以在其他应用程序上引用的插件WPF应用程序,而后者可以更改前者的样式。

我的示例基于Xceed的BusyIndi​​cator。 我在插件WPF应用程序中具有BusyIndi​​cator的样式,并且希望在其他应用程序上更改该BusyIndi​​cator的样式。

例:

WPF插件应用程序:我们称之为OverrideBusyIndi​​cator。 解决方案如下图所示,其中存在一个包含BusyIndi​​cator的MainWindow,并且BusyIndi​​cator样式位于BusyContextResourceDictionary.xaml中

在此处输入图片说明

BusyContextResourceDictionary.xaml的内容是这样的:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type xceed:BusyIndicator}">
    <Setter Property="BusyContentTemplate">
        <Setter.Value>
            <DataTemplate>
                <StackPanel Margin="4">
                    <TextBlock Text="Downloading Email" FontWeight="Bold" HorizontalAlignment="Center"/>
                    <StackPanel Margin="4">
                        <TextBlock Text="Downloading message 4/10..."/>
                        <ProgressBar Value="40" Height="15"/>
                    </StackPanel>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Content="Pause" HorizontalAlignment="Right" Margin="0 0 2 0"/>
                        <Button Grid.Column="1" Content="Cancel" HorizontalAlignment="Left" Margin="2 0 0 0"/>
                    </Grid>
                </StackPanel>
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

在此处输入图片说明

我创建了另一个解决方案,该解决方案将引用上面的程序集。 我们将其称为OverrideBusyIndi​​cator2。 这个没有主窗口,它的App.xaml只是调用了另一个OverrideBusyIndi​​cator.MainWindow。 然后, 添加了我希望覆盖的BusyContextResourceDictionary2.xaml以覆盖BusyIndi​​cator的样式,但事实并非如此。 有什么办法可以实现这种行为?

<Application x:Class="OverrideBusyIndicator2.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
         StartupUri="pack://application:,,,/OverrideBusyIndicator;component/MainWindow.xaml">
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="BusyContextResourceDictionary2.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

出于示例目的,BusyContextResourceDictionary2.xaml只会将文本块文本从“下载电子邮件”更改为“不下载电子邮件”。

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:xceed="http://schemas.xceed.com/wpf/xaml/toolkit"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="pack://application:,,,/OverrideBusyIndicator;component/BusyContextResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>

<!--I am using BasedOn to override the BusyContextResourceDictionary.xaml-->

<Style TargetType="{x:Type xceed:BusyIndicator}" BasedOn="{StaticResource {x:Type xceed:BusyIndicator}}">
            <Setter Property="BusyContentTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <StackPanel Margin="4">
                            <TextBlock Text="NOT Downloading Email" FontWeight="Bold" HorizontalAlignment="Center"/>**

看到xceed:BusyIndi​​cator控件的样式将很有帮助。 您可能需要为控件定义默认样式键属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM