I have a DLL
containing a WPF window, created through a project of type WPF User Control Library
.
How do I display this window from another project?
Window's XAML (DLL project):
<Window x:Class="UmaJanelaComUmBotao.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UmaJanelaComUmBotao"
mc:Ignorable="d"
Title="Window1" Height="300" Width="300">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="112,55,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
Window C # Code (DLL project):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace UmaJanelaComUmBotao
{
/// <summary>
/// Lógica interna para Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1 ( )
{
InitializeComponent ( );
}
}
}
If codebehind is required I can also post.
Main method (project .exe)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UmaJanelaComUmBotao;
namespace OExcutavel
{
class Program
{
static void Main ( string[ ] args )
{
//Como chamar Window1 a partir daqui
}
}
}
codebehind:
namespace UmaJanelaComUmBotao {
/// <summary>
/// Window1
/// </summary>
public partial class Window1 : System.Windows.Window, System.Windows.Markup.IComponentConnector {
#line 10 "..\..\Window1.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button button;
#line default
#line hidden
private bool _contentLoaded;
/// <summary>
/// InitializeComponent
/// </summary>
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public void InitializeComponent() {
if (_contentLoaded) {
return;
}
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/UmaJanelaComUmBotao;component/window1.xaml", System.UriKind.Relative);
#line 1 "..\..\Window1.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
switch (connectionId)
{
case 1:
this.button = ((System.Windows.Controls.Button)(target));
return;
}
this._contentLoaded = true;
}
}
}