【问题标题】:How to use the Windows 8 default style (Xaml) in an Outlook plugin如何在 Outlook 插件中使用 Windows 8 默认样式 (Xaml)
【发布时间】:2014-12-15 20:42:33
【问题描述】:

我目前正在创建一个带有设置窗口的 Outlook 插件。设置窗口将类似于 Outlook 2013 中的帐户设置窗口。

我正在 Windows 8.1 机器上为 Outlook 创建这个插件。

现在,当您创建 Outlook 插件时,您可以添加一个表单,但这是一个 Windows 表单,这对我不利。因此,我搜索了如何为 Outlook 插件创建 WPF 窗口,基本上,您选择添加 XAML UserControl,其源代码如下所示:

<UserControl x:Class="OutlookAddIn1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

    </Grid>
</UserControl>

现在,您可以通过将UserControl 更改为Window 来轻松创建一个窗口。另外,你需要从后面代码中的基类Window继承。

源将如下所示:

<Window x:Class="OutlookAddIn1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>

    </Grid>
</Window>

现在,我将在刚刚创建的 WPF 窗口/用户控件上添加一个按钮。

当您运行应用程序并打开刚刚创建的窗口时,您将看到以下内容:

它工作正常,我看到一个按钮,但为了保持一致,我希望我的按钮和所有未来的控件具有与我的本地 Windows 环境 (Windows 8.1) 上的控件相同的外观。

这是 Windows 8.1 上默认 Windows 样式的屏幕截图

如您所见,我的实现与默认的 windows 实现之间肯定存在变化。

所以,问题很简单:在 Outlook 插件中,如何创建应用程序以使控件的样式与 Windows 控件的样式匹配?

我已经在网上搜索了很多,但找不到可靠的解决方案。 好像Windows 8中的样式叫做Aero2。

我确实在以下位置找到了对 Aero2 的引用:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\SystemThemes\Wpf

在这里我确实找到了很多 Xaml 文件。

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF

这里有一个引用 dll,名为:'PresentationFramework.Aero2.dll'

有人能解释一下我是如何做到这一点的吗?太好了,因为我希望我的插件具有与默认 Windows 样式相同的样式。

【问题讨论】:

    标签: c# wpf windows xaml outlook


    【解决方案1】:

    经过大量搜索,我发现 WPF 带有自己的样式,根本不链接到 Windows。

    因此,唯一的解决方案是创建您自己的自定义控件。

    所以,我已经做到了,这是第一个非常基本的版本。完全不依赖输入参数。

    这只是一个关于如何设置按钮样式以使其具有默认 Windows 8.1 外观的演示:

    <ControlTemplate x:Key="ButtonControlTemplate1" TargetType="{x:Type Button}">
        <Border x:Name="buttonBaseBorder" BorderBrush="#ACACAC" BorderThickness="1" SnapsToDevicePixels="True">
            <Grid x:Name="buttonBase" Width="84" Height="22" VerticalAlignment="Center">
                <Grid.Background>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                        <GradientStop Color="#F0F0F0" Offset="0" />
                        <GradientStop Color="#E5E5E5" Offset="1" />
                    </LinearGradientBrush>
                </Grid.Background>
                <Label HorizontalContentAlignment="Center" Foreground="Black" Width="84" Content="{TemplateBinding Content}" Padding="0" Margin="0" VerticalContentAlignment="Center"  />
            </Grid>
        </Border>
    
        <!-- Set the triggers that are needed for the button. -->
        <ControlTemplate.Triggers>
            <!-- Trigger for mouse over on the button. -->
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="buttonBase" Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                            <GradientStop Color="#ECF4FC" Offset="0.0" />
                            <GradientStop Color="#DCECFC" Offset="1.0" />
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
    
                <Setter TargetName="buttonBaseBorder" Property="BorderBrush" Value="#7EB4EA" />
            </Trigger>
    
            <!-- Trigger for when the button is the default one. -->
            <Trigger Property="IsDefault" Value="True">
                <Setter TargetName="buttonBaseBorder" Property="BorderBrush" Value="#3399FF" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 2022-01-03
      相关资源
      最近更新 更多