Skip to content

Feature/improve label content #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,8 @@ private void ShowBasicApplicationSettingsDialogBoxCommandHandler()
}

private static List<ILabelControlBase> CreateLabelControlsColumn1()
=> new()
{
=>
[
new LabelTextBox
{
LabelText = "FirstName",
Expand All @@ -656,11 +656,11 @@ private static List<ILabelControlBase> CreateLabelControlsColumn1()
IsMandatory = true,
MinLength = 2,
},
};
];

private static List<ILabelControlBase> CreateLabelControlsColumn2()
=> new()
{
=>
[
new LabelIntegerBox
{
LabelText = "Age",
Expand All @@ -670,11 +670,11 @@ private static List<ILabelControlBase> CreateLabelControlsColumn2()
{
LabelText = "Note",
},
};
];

private static List<ILabelControlBase> CreateLabelControlsColumn3()
=> new()
{
=>
[
new LabelCheckBox
{
LabelText = "Use Foo",
Expand All @@ -691,7 +691,7 @@ private static List<ILabelControlBase> CreateLabelControlsColumn3()
{ "Item5", "Item 5" },
},
},
};
];

private string CreateJson(
string value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:atc="https://github.com/atc-net/atc-wpf/tree/main/schemas"
xmlns:atcTranslation="https://github.com/atc-net/atc-wpf/tree/main/schemas/translations"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogs="clr-namespace:Atc.Wpf.Theming.Themes.Dialogs;assembly=Atc.Wpf.Theming"
xmlns:local="clr-namespace:Atc.Wpf.Controls.Dialogs"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:settingsControls="clr-namespace:Atc.Wpf.Controls.SettingsControls"
x:Name="DialogApplicationSettings"
Title="?Application Settings"
Title="{atcTranslation:Resx ResxName=Atc.Wpf.Controls.Resources.Miscellaneous,
Key=ApplicationSettings}"
Width="550"
Height="300"
d:DataContext="{d:DesignInstance Type=local:BasicApplicationSettingsDialogBoxViewModel}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ public BasicApplicationSettingsDialogBox()
InitializeComponent();
}

public BasicApplicationSettingsDialogBox(
IBasicApplicationSettingsDialogBoxViewModel viewModel)
{
InitializeComponent();

DataContext = viewModel;
}

public string GetDataAsJson()
=> DataContext is BasicApplicationSettingsDialogBoxViewModel vm
? vm.ToJson()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Atc.Wpf.Controls.Dialogs;

public interface IBasicApplicationSettingsDialogBoxViewModel : IViewModelBase
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ReSharper disable CheckNamespace
namespace Atc.Wpf.Controls.LabelControls;

public static class LabelContentExtensions
{
public static T? GetViewModel<T>(
this LabelContent labelContent)
where T : ViewModelBase
{
ArgumentNullException.ThrowIfNull(labelContent);

return labelContent.Content is FrameworkElement frameworkElement
? frameworkElement.DataContext as T
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ public static bool IsValid(
ArgumentNullException.ThrowIfNull(labelControls);
ArgumentException.ThrowIfNullOrEmpty(identifier);

return labelControls.Find(x => x.Identifier == identifier) as T;
if (labelControls.Find(x => x.Identifier == identifier || x.GetFullIdentifier() == identifier) is T labelControl)
{
return labelControl;
}

foreach (var lc in labelControls)
{
if (lc is FrameworkElement { Tag: not null } frameworkElement &&
frameworkElement.Tag.ToString() == identifier)
{
return lc as T;
}
}

return null;
}
}
11 changes: 11 additions & 0 deletions src/Atc.Wpf.Controls/LabelControls/LabelControlsFormColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ public Dictionary<string, object> GetKeyValues()
result.Add(control.GetFullIdentifier(), (Color)color);
}

break;
case LabelContent labelContent:
if (labelContent.Content is FrameworkElement { DataContext: ViewModelBase } labelContentFrameworkElement)
{
var tag = labelContent.Tag?.ToString();
if (!string.IsNullOrEmpty(tag))
{
result.Add(tag, labelContentFrameworkElement.DataContext);
}
}

break;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.da-DK.resx
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@
<data name="OpenRecentFileOnStartup" xml:space="preserve">
<value>Åbn den seneste fil ved opstart</value>
</data>
<data name="ApplicationSettings" xml:space="preserve">
<value>Applikationsindstillinger</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,7 @@
<data name="OpenRecentFileOnStartup" xml:space="preserve">
<value>Öffnen Sie die zuletzt verwendete Datei beim Start</value>
</data>
<data name="ApplicationSettings" xml:space="preserve">
<value>Anwendungseinstellungen</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/Atc.Wpf.Controls/Resources/Miscellaneous.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ApplicationSettings" xml:space="preserve">
<value>Application Settings</value>
</data>
<data name="AvailableColors" xml:space="preserve">
<value>Available Colors</value>
</data>
Expand Down
Loading