12 changed files with 332 additions and 44 deletions
@ -0,0 +1,65 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel; |
|||
using System.Linq; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Perspex.Designer.AppHost |
|||
{ |
|||
public class HostedAppModel : INotifyPropertyChanged |
|||
{ |
|||
private IntPtr _nativeWindowHandle; |
|||
private string _error; |
|||
private string _errorDetails; |
|||
|
|||
public IntPtr NativeWindowHandle |
|||
{ |
|||
get { return _nativeWindowHandle; } |
|||
set |
|||
{ |
|||
if (value.Equals(_nativeWindowHandle)) return; |
|||
_nativeWindowHandle = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public string Error |
|||
{ |
|||
get { return _error; } |
|||
private set |
|||
{ |
|||
if (value == _error) return; |
|||
_error = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public string ErrorDetails |
|||
{ |
|||
get { return _errorDetails; } |
|||
private set |
|||
{ |
|||
if (value == _errorDetails) return; |
|||
_errorDetails = value; |
|||
OnPropertyChanged(); |
|||
} |
|||
} |
|||
|
|||
public void SetError(string error, string details = null) |
|||
{ |
|||
Error = error; |
|||
ErrorDetails = details; |
|||
} |
|||
|
|||
public event PropertyChangedEventHandler PropertyChanged; |
|||
|
|||
[NotifyPropertyChangedInvocator] |
|||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) |
|||
{ |
|||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Perspex.Designer |
|||
{ |
|||
class DesignerAppHost |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
<UserControl x:Class="Perspex.Designer.InProcDesigner.InProcDesignerView" |
|||
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:appHost="clr-namespace:Perspex.Designer.AppHost" |
|||
mc:Ignorable="d" |
|||
d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance appHost:HostedAppModel}"> |
|||
<DockPanel> |
|||
<Border x:Name="ErrorPanel" DockPanel.Dock="Bottom" BorderBrush="Red" BorderThickness="3" Padding="3"> |
|||
<StackPanel Orientation="Horizontal"> |
|||
<TextBlock Text="{Binding Error}" FontSize="16"/> |
|||
<TextBlock x:Name="DetailsBlock" FontSize="16"> |
|||
<Run> (</Run><Hyperlink Click="Hyperlink_OnClick">View details</Hyperlink><Run>)</Run> |
|||
</TextBlock> |
|||
</StackPanel> |
|||
</Border> |
|||
<WindowsFormsHost x:Name="WindowHostControl"/> |
|||
</DockPanel> |
|||
</UserControl> |
|||
@ -0,0 +1,84 @@ |
|||
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.Navigation; |
|||
using System.Windows.Shapes; |
|||
using Perspex.Designer.AppHost; |
|||
|
|||
namespace Perspex.Designer.InProcDesigner |
|||
{ |
|||
/// <summary>
|
|||
/// Interaction logic for InProcDesignerView.xaml
|
|||
/// </summary>
|
|||
public partial class InProcDesignerView : UserControl |
|||
{ |
|||
private readonly HostedAppModel _appModel; |
|||
private readonly WindowHost _host; |
|||
|
|||
public InProcDesignerView(HostedAppModel appModel) |
|||
{ |
|||
_appModel = appModel; |
|||
InitializeComponent(); |
|||
DataContext = _appModel; |
|||
_appModel.PropertyChanged += ModelPropertyChanged; |
|||
WindowHostControl.Child = _host = new WindowHost(); |
|||
HandleVisibility(); |
|||
HandleWindow(); |
|||
|
|||
} |
|||
|
|||
private void ModelPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) |
|||
{ |
|||
if (e.PropertyName == nameof(HostedAppModel.Error) || e.PropertyName == nameof(HostedAppModel.ErrorDetails)) |
|||
HandleVisibility(); |
|||
if (e.PropertyName == nameof(HostedAppModel.NativeWindowHandle)) |
|||
HandleWindow(); |
|||
} |
|||
|
|||
private void HandleWindow() |
|||
{ |
|||
_host.SetWindow(_appModel.NativeWindowHandle); |
|||
} |
|||
|
|||
private void HandleVisibility() |
|||
{ |
|||
ErrorPanel.Visibility = string.IsNullOrEmpty(_appModel.Error) |
|||
? Visibility.Collapsed |
|||
: Visibility.Visible; |
|||
DetailsBlock.Visibility = string.IsNullOrWhiteSpace(_appModel.ErrorDetails) |
|||
? Visibility.Collapsed |
|||
: Visibility.Visible; |
|||
} |
|||
|
|||
|
|||
|
|||
public InProcDesignerView() |
|||
{ |
|||
|
|||
} |
|||
|
|||
private void Hyperlink_OnClick(object sender, RoutedEventArgs e) |
|||
{ |
|||
var wnd = new Window() |
|||
{ |
|||
Content = new TextBox() |
|||
{ |
|||
IsReadOnly = true, |
|||
AcceptsReturn = true, |
|||
TextWrapping = TextWrapping.Wrap, |
|||
Text = _appModel.ErrorDetails |
|||
} |
|||
}; |
|||
wnd.ShowDialog(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="JetBrains.Annotations" version="9.2.0" targetFramework="net45" /> |
|||
</packages> |
|||
Loading…
Reference in new issue