Skip to content

Commit

Permalink
Added about dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandKoenig committed Dec 4, 2020
1 parent 082fa84 commit 9683e0c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@
Width="610" Height="400"
x:Class="MessageCommunicator.TestGui.ViewServices.AboutDialogControl">

<Grid>
<TextBox>About ;)</TextBox>
</Grid>
<DockPanel LastChildFill="True">
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom"
HorizontalAlignment="Right">
<StackPanel.Styles>
<Style Selector="Button">
<Setter Property="Width" Value="125" />
<Setter Property="Margin" Value="3" />
</Style>
</StackPanel.Styles>

<Button Content="OK" IsDefault="True" Command="{Binding Path=Command_Close}" />
</StackPanel>

<localRoot:PropertyGrid SelectedObject="{Binding Path=Self}" />
</DockPanel>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace MessageCommunicator.TestGui.ViewServices
{
public class AboutDialogControl : OwnUserControlDialog<OwnViewModelBase>
public class AboutDialogControl : OwnUserControlDialog<AboutDialogViewModel>
{
public AboutDialogControl()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public AboutDialogService(DialogHostControl host)
public Task ShowAboutDialogAsync()
{
var aboutDialogControl = new AboutDialogControl();
return _host.ShowDialogAsync(aboutDialogControl, "About");
aboutDialogControl.DataContext = new AboutDialogViewModel();
return aboutDialogControl.ShowControlDialogAsync(_host, "About");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reactive;
using System.Reflection;
using System.Runtime.Versioning;
using System.Text;
using Avalonia.Controls;
using ReactiveUI;

namespace MessageCommunicator.TestGui.ViewServices
{
public class AboutDialogViewModel : OwnViewModelBase
{
public string Name
{
get
{
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>();
return asmAttribute?.Product ?? string.Empty;
}
}

public string Version
{
get
{
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return asmAttribute?.InformationalVersion ?? string.Empty;
}
}

public string Description
{
get
{
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>();
return asmAttribute?.Description ?? string.Empty;
}
}

public string Homepage
{
get => "https://github.com/RolandKoenig/MessageCommunicator";
}

public string Author
{
get
{
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCompanyAttribute>();
return asmAttribute?.Company ?? string.Empty;
}
}

public string Copyright
{
get
{
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>();
return asmAttribute?.Copyright ?? string.Empty;
}
}

public string TargetFramework
{
get
{
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<TargetFrameworkAttribute>();
return asmAttribute?.FrameworkName ?? string.Empty;
}
}

public string AvaloniaVersion
{
get
{
var asmAttribute = typeof(Window).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return asmAttribute?.InformationalVersion?? string.Empty;
}
}

[Browsable(false)]
public ReactiveCommand<Unit, Unit> Command_Close { get; }

[Browsable(false)]
public AboutDialogViewModel Self => this;

public AboutDialogViewModel()
{
this.Command_Close = ReactiveCommand.Create(() => this.CloseWindow(null));
}
}
}
21 changes: 2 additions & 19 deletions MessageCommunicator.TestGui/_Util/_View/DialogHostControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public DialogHostControl()
}

public void ShowDialog(Control controlToShow, string headerText)
{
this.ShowDialogAsync(controlToShow, headerText);
}

public Task ShowDialogAsync(Control controlToShow, string headerText)
{
var currentChild = controlToShow;
var currentChildInitialSize = new Size(currentChild.Width, currentChild.Height);
Expand All @@ -61,11 +56,9 @@ public Task ShowDialogAsync(Control controlToShow, string headerText)
var currentBackground = new Grid();
currentBackground.Background = _backgroundDialog;

var taskComplSource = new TaskCompletionSource<object?>();
_children.Push(new ChildInfo(
currentChild, currentChildBorder,
currentChildInitialSize, currentBackground,
taskComplSource));
currentChildInitialSize, currentBackground));

this.Children.Add(currentBackground);
this.Children.Add(borderControl);
Expand All @@ -77,8 +70,6 @@ public Task ShowDialogAsync(Control controlToShow, string headerText)
}

this.UpdateBorderSize();

return taskComplSource.Task;
}

public void CloseDialog()
Expand All @@ -89,7 +80,6 @@ public void CloseDialog()
}
this.Children.Remove(removedChild.ChildBorder);
this.Children.Remove(removedChild.ChildBackground);
removedChild.TaskComplSource.TrySetResult(null);

if (_children.Count == 0)
{
Expand Down Expand Up @@ -169,21 +159,14 @@ public Size InitialSize
get;
}

public TaskCompletionSource<object?> TaskComplSource
{
get;
}

internal ChildInfo(
Control child, Control childBorder,
Size initialSize, Grid childBackground,
TaskCompletionSource<object?> taskComplSource)
Size initialSize, Grid childBackground)
{
this.Child = child;
this.ChildBorder = childBorder;
this.InitialSize = initialSize;
this.ChildBackground = childBackground;
this.TaskComplSource = taskComplSource;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public PropertyValueType ValueType
set;
}

public bool IsReadOnly
{
get;
set;
}

internal ConfigurablePropertyMetadata(PropertyDescriptor propertyInfo, object hostObject, IPropertyContractResolver? propertyContractResolver)
{
_descriptor = propertyInfo;
Expand All @@ -70,6 +76,7 @@ internal ConfigurablePropertyMetadata(PropertyDescriptor propertyInfo, object ho
this.CategoryName = categoryAttrib?.Category ?? string.Empty;

this.PropertyName = propertyInfo.Name;
this.IsReadOnly = propertyInfo.IsReadOnly;

this.PropertyDisplayName = propertyInfo.Name;
var displayNameAttrib = this.GetCustomAttribute<DisplayNameAttribute>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Layout;
using SharpDX.DXGI;

namespace MessageCommunicator.TestGui
{
Expand Down Expand Up @@ -44,6 +45,7 @@ public class PropertyGridEditControlFactory
default:
throw new ArgumentOutOfRangeException($"Unsupported value {property.ValueType}");
}

return ctrlValueEdit;
}

Expand All @@ -56,6 +58,7 @@ protected virtual Control CreateCheckBoxControl(
nameof(property.ValueAccessor),
BindingMode.TwoWay);
ctrlCheckBox.HorizontalAlignment = HorizontalAlignment.Left;
ctrlCheckBox.IsEnabled = !property.IsReadOnly;
return ctrlCheckBox;
}

Expand All @@ -68,6 +71,7 @@ protected virtual Control CreateTextBoxControl(
nameof(property.ValueAccessor),
BindingMode.TwoWay);
ctrlTextBox.Width = double.NaN;
ctrlTextBox.IsReadOnly = property.IsReadOnly;
return ctrlTextBox;
}

Expand All @@ -81,6 +85,7 @@ protected virtual Control CreateEnumControl(
nameof(property.ValueAccessor),
BindingMode.TwoWay);
ctrlComboBox.Width = double.NaN;
ctrlComboBox.IsEnabled = !property.IsReadOnly;
return ctrlComboBox;
}

Expand All @@ -99,6 +104,7 @@ protected virtual Control CreateEncodingWebNameControl(
nameof(property.ValueAccessor),
BindingMode.TwoWay);
ctrlComboBoxEnc.Width = double.NaN;
ctrlComboBoxEnc.IsEnabled = !property.IsReadOnly;

var ctrlEncDescLabel = new TextBlock();
ctrlEncDescLabel[!TextBlock.TextProperty] = new Binding(
Expand Down Expand Up @@ -139,6 +145,7 @@ protected virtual Control CreateTextAndHexadecimalEditControl(
nameof(property.ValueAccessor),
BindingMode.TwoWay);
ctrlTextBox1.Width = double.NaN;
ctrlTextBox1.IsReadOnly = property.IsReadOnly;

var hexTextBinding = new Binding(
nameof(property.ValueAccessor),
Expand All @@ -160,6 +167,7 @@ protected virtual Control CreateTextAndHexadecimalEditControl(
var ctrlTextBox2 = new TextBox();
ctrlTextBox2[!TextBox.TextProperty] = hexTextBinding;
ctrlTextBox2.Width = double.NaN;
ctrlTextBox2.IsReadOnly = property.IsReadOnly;

otherProperty.RegisterWeakPropertyChangedTarget(
new WeakReference(ctrlTextBox2),
Expand Down

0 comments on commit 9683e0c

Please sign in to comment.