WPF in Office Vstso Anwendungen
Diese Code-Beispiel zeigt, wie man WPF Controls und Formulare
in eine Word Office Ribbonbar/Menü Anwendung einbindet.
Dabei wird ein VSTO Addin für Word erstellt und
anschliessend ein WPF User Control in das Project eingefügt.
Durch Ändern der Eintragung: UserControl zu Window wird das
WPF Control in vollem Umfang in die Word-Ribbonbar Anwendung eingebettet.
WPF UserContro
hinzufügen
Dann fügt man der VSTO Anwendung ein WPF UserControl hinzu
Unter Project->Add->New
Item->WPF->User Control (WPF)
UserControl zu Window
ändern
Im WPF UserControl ändert man das <UserControl> Tag
auf <Window>
Rename UserControl to Window
<Window x:Class="wpf_in_Word_addin.FormWPF"
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"
xmlns:local="clr-namespace:wpf_in_Word_addin"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="Red">
<Button Content="Button" HorizontalAlignment="Left" Margin="105,123,0,0" VerticalAlignment="Top"
Width="201" Height="194"/>
<Label Content="This is a WPF FORM or UserControl" HorizontalAlignment="Left"
Margin="67,43,0,0" VerticalAlignment="Top"
Height="42" Width="71"/>
</Grid>
</Window>
|
C# Code Class UserControl zu Window
In der Codebehind datei formWPF.xaml.cs ändern man ebenfalls : UserControl zu : Window
using System.Windows;
namespace wpf_in_Word_addin
{
//*Change UserControl to myForm : Window
public partial class FormWPF : Window
{
public FormWPF()
{
InitializeComponent();
}
}
}
|
WPF Form öffnen
Anschliessend kann man in der Office Anwendung hier im
Button-Click Evente des Buttons im Ribbonbar das WPF Formular öffnen
Mit WPFform.show()
using Microsoft.Office.Tools.Ribbon;
namespace wpf_in_Word_addin
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
//--< open WPF Form >--
FormWPF form = new FormWPF();
form.Show();
//--</ open WPF Form >--
}
}
}
|
Tutorial in Youtube
https://www.youtube.com/watch?v=mwRnY3LXsxQ&feature=youtu.be
Betrifft:
MS Word,
Excel Access Outlook Powerpoint
VSTO Ribbonbar
Addin Addins Interop Anwendungen
Office 2013
2016 Office 365