Reputation: 37
I have an Outlook vsto which adds a Button
to the preview pane of the selected mail.
For now the vsto only has the purpose of adding the button, but additional functionality is to come.
Additional I have a WPF Window
which opens when the Button
is clicked.
private void ArchiveButton_Click(object sender, EventArgs e)
{
var mail = (Outlook.MailItem)OutlookItem; // currently selected mail.
var app = new App();
app.InitializeComponent();
app.Run(new MainWindow(mail));
}
As you can see I can run the App.xaml to get the stylings and pass the parameter mail
to the window.
In this MainWindow
I edit some metadata and initiate the storing process, so I need that Outlook.MailItem object.
The solution I found was to have two constructors of MainWindow. One called by app.InitializeComponent()
which seems to load the styling and is immediately closed and one called by app.Run(new MainWindow(mail))
which I actually use.
public MainWindow()
{
Close();
}
public MainWindow(Outlook.MailItem mail)
{
InitializeComponent();
SearchTextBox.Text = mail == null ? "null" : "mail"; // checking if the WPF got the object
MailItem = mail;
...
}
My question here is:
Is there a cleaner/ better solution to get both, styling and the parameter?
Upvotes: 0
Views: 146
Reputation: 1804
As you are manually creating the WPF main window from code, remove the StartupUri
definition from App.xaml
file.
If it is defined, it will be automatically created by WPF infrastructure, hence the window blinking.
Upvotes: 1