Skip to content

Commit 0a607ef

Browse files
Merge pull request #116 from atc-net/feature/Improve-LabelContent
Feature/improve label content
2 parents 782f7e1 + 9058a47 commit 0a607ef

11 files changed

+85
-11
lines changed

sample/Atc.Wpf.Sample/SamplesWpfControls/DialogBoxes/StandardDialogBoxViewModel.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,8 @@ private void ShowBasicApplicationSettingsDialogBoxCommandHandler()
642642
}
643643

644644
private static List<ILabelControlBase> CreateLabelControlsColumn1()
645-
=> new()
646-
{
645+
=>
646+
[
647647
new LabelTextBox
648648
{
649649
LabelText = "FirstName",
@@ -656,11 +656,11 @@ private static List<ILabelControlBase> CreateLabelControlsColumn1()
656656
IsMandatory = true,
657657
MinLength = 2,
658658
},
659-
};
659+
];
660660

661661
private static List<ILabelControlBase> CreateLabelControlsColumn2()
662-
=> new()
663-
{
662+
=>
663+
[
664664
new LabelIntegerBox
665665
{
666666
LabelText = "Age",
@@ -670,11 +670,11 @@ private static List<ILabelControlBase> CreateLabelControlsColumn2()
670670
{
671671
LabelText = "Note",
672672
},
673-
};
673+
];
674674

675675
private static List<ILabelControlBase> CreateLabelControlsColumn3()
676-
=> new()
677-
{
676+
=>
677+
[
678678
new LabelCheckBox
679679
{
680680
LabelText = "Use Foo",
@@ -691,7 +691,7 @@ private static List<ILabelControlBase> CreateLabelControlsColumn3()
691691
{ "Item5", "Item 5" },
692692
},
693693
},
694-
};
694+
];
695695

696696
private string CreateJson(
697697
string value)

src/Atc.Wpf.Controls/Dialogs/BasicApplicationSettingsDialogBox.xaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
6+
xmlns:atcTranslation="https://github.com/atc-net/atc-wpf/tree/main/schemas/translations"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
78
xmlns:dialogs="clr-namespace:Atc.Wpf.Theming.Themes.Dialogs;assembly=Atc.Wpf.Theming"
89
xmlns:local="clr-namespace:Atc.Wpf.Controls.Dialogs"
910
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1011
xmlns:settingsControls="clr-namespace:Atc.Wpf.Controls.SettingsControls"
1112
x:Name="DialogApplicationSettings"
12-
Title="?Application Settings"
13+
Title="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous,
14+
Key=ApplicationSettings}"
1315
Width="550"
1416
Height="300"
1517
d:DataContext="{d:DesignInstance Type=local:BasicApplicationSettingsDialogBoxViewModel}"

src/Atc.Wpf.Controls/Dialogs/BasicApplicationSettingsDialogBox.xaml.cs

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public BasicApplicationSettingsDialogBox()
1010
InitializeComponent();
1111
}
1212

13+
public BasicApplicationSettingsDialogBox(
14+
IBasicApplicationSettingsDialogBoxViewModel viewModel)
15+
{
16+
InitializeComponent();
17+
18+
DataContext = viewModel;
19+
}
20+
1321
public string GetDataAsJson()
1422
=> DataContext is BasicApplicationSettingsDialogBoxViewModel vm
1523
? vm.ToJson()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace Atc.Wpf.Controls.Dialogs;
2+
3+
public interface IBasicApplicationSettingsDialogBoxViewModel : IViewModelBase
4+
{
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// ReSharper disable CheckNamespace
2+
namespace Atc.Wpf.Controls.LabelControls;
3+
4+
public static class LabelContentExtensions
5+
{
6+
public static T? GetViewModel<T>(
7+
this LabelContent labelContent)
8+
where T : ViewModelBase
9+
{
10+
ArgumentNullException.ThrowIfNull(labelContent);
11+
12+
return labelContent.Content is FrameworkElement frameworkElement
13+
? frameworkElement.DataContext as T
14+
: null;
15+
}
16+
}

src/Atc.Wpf.Controls/LabelControls/Extensions/LabelControlBaseExtensions.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ public static bool IsValid(
1515
ArgumentNullException.ThrowIfNull(labelControls);
1616
ArgumentException.ThrowIfNullOrEmpty(identifier);
1717

18-
return labelControls.Find(x => x.Identifier == identifier) as T;
18+
if (labelControls.Find(x => x.Identifier == identifier || x.GetFullIdentifier() == identifier) is T labelControl)
19+
{
20+
return labelControl;
21+
}
22+
23+
foreach (var lc in labelControls)
24+
{
25+
if (lc is FrameworkElement { Tag: not null } frameworkElement &&
26+
frameworkElement.Tag.ToString() == identifier)
27+
{
28+
return lc as T;
29+
}
30+
}
31+
32+
return null;
1933
}
2034
}

src/Atc.Wpf.Controls/LabelControls/LabelControlsFormColumn.cs

+11
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ public Dictionary<string, object> GetKeyValues()
173173
result.Add(control.GetFullIdentifier(), (Color)color);
174174
}
175175

176+
break;
177+
case LabelContent labelContent:
178+
if (labelContent.Content is FrameworkElement { DataContext: ViewModelBase } labelContentFrameworkElement)
179+
{
180+
var tag = labelContent.Tag?.ToString();
181+
if (!string.IsNullOrEmpty(tag))
182+
{
183+
result.Add(tag, labelContentFrameworkElement.DataContext);
184+
}
185+
}
186+
176187
break;
177188
}
178189
}

src/Atc.Wpf.Controls/Resources/Miscellaneous.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Atc.Wpf.Controls/Resources/Miscellaneous.da-DK.resx

+3
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,7 @@
174174
<data name="OpenRecentFileOnStartup" xml:space="preserve">
175175
<value>Åbn den seneste fil ved opstart</value>
176176
</data>
177+
<data name="ApplicationSettings" xml:space="preserve">
178+
<value>Applikationsindstillinger</value>
179+
</data>
177180
</root>

src/Atc.Wpf.Controls/Resources/Miscellaneous.de-DE.resx

+3
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,7 @@
174174
<data name="OpenRecentFileOnStartup" xml:space="preserve">
175175
<value>Öffnen Sie die zuletzt verwendete Datei beim Start</value>
176176
</data>
177+
<data name="ApplicationSettings" xml:space="preserve">
178+
<value>Anwendungseinstellungen</value>
179+
</data>
177180
</root>

src/Atc.Wpf.Controls/Resources/Miscellaneous.resx

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120+
<data name="ApplicationSettings" xml:space="preserve">
121+
<value>Application Settings</value>
122+
</data>
120123
<data name="AvailableColors" xml:space="preserve">
121124
<value>Available Colors</value>
122125
</data>

0 commit comments

Comments
 (0)