簡體   English   中英

如何在Outlook插件中使用Windows 8默認樣式(Xaml)

[英]How to use the Windows 8 default style (Xaml) in an Outlook plugin

我當前正在創建一個具有設置窗口的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繼承。

源將如下所示:

<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窗口/ UserControl上添加一個按鈕。

當您運行該應用程序並打開剛剛創建的窗口時,您將看到以下內容:

在此處輸入圖片說明

它可以正常工作,並且我看到一個按鈕,但是為了保持一致,我希望我的按鈕以及所有將來的控件都具有與本機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樣式相同的樣式。

經過大量搜索后,我發現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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM