Skip to content

Commit 9683e0c

Browse files
committed
Added about dialog
1 parent 082fa84 commit 9683e0c

7 files changed

Lines changed: 129 additions & 24 deletions

File tree

MessageCommunicator.TestGui/ViewServices/_AboutDialog/AboutDialogControl.xaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@
88
Width="610" Height="400"
99
x:Class="MessageCommunicator.TestGui.ViewServices.AboutDialogControl">
1010

11-
<Grid>
12-
<TextBox>About ;)</TextBox>
13-
</Grid>
11+
<DockPanel LastChildFill="True">
12+
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom"
13+
HorizontalAlignment="Right">
14+
<StackPanel.Styles>
15+
<Style Selector="Button">
16+
<Setter Property="Width" Value="125" />
17+
<Setter Property="Margin" Value="3" />
18+
</Style>
19+
</StackPanel.Styles>
20+
21+
<Button Content="OK" IsDefault="True" Command="{Binding Path=Command_Close}" />
22+
</StackPanel>
23+
24+
<localRoot:PropertyGrid SelectedObject="{Binding Path=Self}" />
25+
</DockPanel>
1426
</UserControl>

MessageCommunicator.TestGui/ViewServices/_AboutDialog/AboutDialogControl.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace MessageCommunicator.TestGui.ViewServices
1212
{
13-
public class AboutDialogControl : OwnUserControlDialog<OwnViewModelBase>
13+
public class AboutDialogControl : OwnUserControlDialog<AboutDialogViewModel>
1414
{
1515
public AboutDialogControl()
1616
{

MessageCommunicator.TestGui/ViewServices/_AboutDialog/AboutDialogService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public AboutDialogService(DialogHostControl host)
1818
public Task ShowAboutDialogAsync()
1919
{
2020
var aboutDialogControl = new AboutDialogControl();
21-
return _host.ShowDialogAsync(aboutDialogControl, "About");
21+
aboutDialogControl.DataContext = new AboutDialogViewModel();
22+
return aboutDialogControl.ShowControlDialogAsync(_host, "About");
2223
}
2324
}
2425
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Reactive;
5+
using System.Reflection;
6+
using System.Runtime.Versioning;
7+
using System.Text;
8+
using Avalonia.Controls;
9+
using ReactiveUI;
10+
11+
namespace MessageCommunicator.TestGui.ViewServices
12+
{
13+
public class AboutDialogViewModel : OwnViewModelBase
14+
{
15+
public string Name
16+
{
17+
get
18+
{
19+
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyProductAttribute>();
20+
return asmAttribute?.Product ?? string.Empty;
21+
}
22+
}
23+
24+
public string Version
25+
{
26+
get
27+
{
28+
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
29+
return asmAttribute?.InformationalVersion ?? string.Empty;
30+
}
31+
}
32+
33+
public string Description
34+
{
35+
get
36+
{
37+
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyDescriptionAttribute>();
38+
return asmAttribute?.Description ?? string.Empty;
39+
}
40+
}
41+
42+
public string Homepage
43+
{
44+
get => "https://github.com/RolandKoenig/MessageCommunicator";
45+
}
46+
47+
public string Author
48+
{
49+
get
50+
{
51+
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCompanyAttribute>();
52+
return asmAttribute?.Company ?? string.Empty;
53+
}
54+
}
55+
56+
public string Copyright
57+
{
58+
get
59+
{
60+
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>();
61+
return asmAttribute?.Copyright ?? string.Empty;
62+
}
63+
}
64+
65+
public string TargetFramework
66+
{
67+
get
68+
{
69+
var asmAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<TargetFrameworkAttribute>();
70+
return asmAttribute?.FrameworkName ?? string.Empty;
71+
}
72+
}
73+
74+
public string AvaloniaVersion
75+
{
76+
get
77+
{
78+
var asmAttribute = typeof(Window).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
79+
return asmAttribute?.InformationalVersion?? string.Empty;
80+
}
81+
}
82+
83+
[Browsable(false)]
84+
public ReactiveCommand<Unit, Unit> Command_Close { get; }
85+
86+
[Browsable(false)]
87+
public AboutDialogViewModel Self => this;
88+
89+
public AboutDialogViewModel()
90+
{
91+
this.Command_Close = ReactiveCommand.Create(() => this.CloseWindow(null));
92+
}
93+
}
94+
}

MessageCommunicator.TestGui/_Util/_View/DialogHostControl.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ public DialogHostControl()
3838
}
3939

4040
public void ShowDialog(Control controlToShow, string headerText)
41-
{
42-
this.ShowDialogAsync(controlToShow, headerText);
43-
}
44-
45-
public Task ShowDialogAsync(Control controlToShow, string headerText)
4641
{
4742
var currentChild = controlToShow;
4843
var currentChildInitialSize = new Size(currentChild.Width, currentChild.Height);
@@ -61,11 +56,9 @@ public Task ShowDialogAsync(Control controlToShow, string headerText)
6156
var currentBackground = new Grid();
6257
currentBackground.Background = _backgroundDialog;
6358

64-
var taskComplSource = new TaskCompletionSource<object?>();
6559
_children.Push(new ChildInfo(
6660
currentChild, currentChildBorder,
67-
currentChildInitialSize, currentBackground,
68-
taskComplSource));
61+
currentChildInitialSize, currentBackground));
6962

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

7972
this.UpdateBorderSize();
80-
81-
return taskComplSource.Task;
8273
}
8374

8475
public void CloseDialog()
@@ -89,7 +80,6 @@ public void CloseDialog()
8980
}
9081
this.Children.Remove(removedChild.ChildBorder);
9182
this.Children.Remove(removedChild.ChildBackground);
92-
removedChild.TaskComplSource.TrySetResult(null);
9383

9484
if (_children.Count == 0)
9585
{
@@ -169,21 +159,14 @@ public Size InitialSize
169159
get;
170160
}
171161

172-
public TaskCompletionSource<object?> TaskComplSource
173-
{
174-
get;
175-
}
176-
177162
internal ChildInfo(
178163
Control child, Control childBorder,
179-
Size initialSize, Grid childBackground,
180-
TaskCompletionSource<object?> taskComplSource)
164+
Size initialSize, Grid childBackground)
181165
{
182166
this.Child = child;
183167
this.ChildBorder = childBorder;
184168
this.InitialSize = initialSize;
185169
this.ChildBackground = childBackground;
186-
this.TaskComplSource = taskComplSource;
187170
}
188171
}
189172
}

MessageCommunicator.TestGui/_Util/_View/_PropertyGrid/ConfigurablePropertyMetadata.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public PropertyValueType ValueType
6060
set;
6161
}
6262

63+
public bool IsReadOnly
64+
{
65+
get;
66+
set;
67+
}
68+
6369
internal ConfigurablePropertyMetadata(PropertyDescriptor propertyInfo, object hostObject, IPropertyContractResolver? propertyContractResolver)
6470
{
6571
_descriptor = propertyInfo;
@@ -70,6 +76,7 @@ internal ConfigurablePropertyMetadata(PropertyDescriptor propertyInfo, object ho
7076
this.CategoryName = categoryAttrib?.Category ?? string.Empty;
7177

7278
this.PropertyName = propertyInfo.Name;
79+
this.IsReadOnly = propertyInfo.IsReadOnly;
7380

7481
this.PropertyDisplayName = propertyInfo.Name;
7582
var displayNameAttrib = this.GetCustomAttribute<DisplayNameAttribute>();

MessageCommunicator.TestGui/_Util/_View/_PropertyGrid/PropertyGridEditControlFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Avalonia.Controls.Primitives;
77
using Avalonia.Data;
88
using Avalonia.Layout;
9+
using SharpDX.DXGI;
910

1011
namespace MessageCommunicator.TestGui
1112
{
@@ -44,6 +45,7 @@ public class PropertyGridEditControlFactory
4445
default:
4546
throw new ArgumentOutOfRangeException($"Unsupported value {property.ValueType}");
4647
}
48+
4749
return ctrlValueEdit;
4850
}
4951

@@ -56,6 +58,7 @@ protected virtual Control CreateCheckBoxControl(
5658
nameof(property.ValueAccessor),
5759
BindingMode.TwoWay);
5860
ctrlCheckBox.HorizontalAlignment = HorizontalAlignment.Left;
61+
ctrlCheckBox.IsEnabled = !property.IsReadOnly;
5962
return ctrlCheckBox;
6063
}
6164

@@ -68,6 +71,7 @@ protected virtual Control CreateTextBoxControl(
6871
nameof(property.ValueAccessor),
6972
BindingMode.TwoWay);
7073
ctrlTextBox.Width = double.NaN;
74+
ctrlTextBox.IsReadOnly = property.IsReadOnly;
7175
return ctrlTextBox;
7276
}
7377

@@ -81,6 +85,7 @@ protected virtual Control CreateEnumControl(
8185
nameof(property.ValueAccessor),
8286
BindingMode.TwoWay);
8387
ctrlComboBox.Width = double.NaN;
88+
ctrlComboBox.IsEnabled = !property.IsReadOnly;
8489
return ctrlComboBox;
8590
}
8691

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

103109
var ctrlEncDescLabel = new TextBlock();
104110
ctrlEncDescLabel[!TextBlock.TextProperty] = new Binding(
@@ -139,6 +145,7 @@ protected virtual Control CreateTextAndHexadecimalEditControl(
139145
nameof(property.ValueAccessor),
140146
BindingMode.TwoWay);
141147
ctrlTextBox1.Width = double.NaN;
148+
ctrlTextBox1.IsReadOnly = property.IsReadOnly;
142149

143150
var hexTextBinding = new Binding(
144151
nameof(property.ValueAccessor),
@@ -160,6 +167,7 @@ protected virtual Control CreateTextAndHexadecimalEditControl(
160167
var ctrlTextBox2 = new TextBox();
161168
ctrlTextBox2[!TextBox.TextProperty] = hexTextBinding;
162169
ctrlTextBox2.Width = double.NaN;
170+
ctrlTextBox2.IsReadOnly = property.IsReadOnly;
163171

164172
otherProperty.RegisterWeakPropertyChangedTarget(
165173
new WeakReference(ctrlTextBox2),

0 commit comments

Comments
 (0)