aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-05 00:35:57 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-05 00:35:57 +0300
commitdd81a94133e1c5117e06e84cbddf45ffec30acfc (patch)
tree13640f05cae1caf4d893d94e73bb0b7a2705110a /Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs
parenta64398732031132ddedd6584c1990a5caa1ae049 (diff)
downloadTango-dd81a94133e1c5117e06e84cbddf45ffec30acfc.tar.gz
Tango-dd81a94133e1c5117e06e84cbddf45ffec30acfc.zip
Dashboard completed ?
Remote job tracking.
Diffstat (limited to 'Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs')
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs47
1 files changed, 41 insertions, 6 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs b/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs
index 73ecd990b..d4f8fdfaa 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.Common/ExtensionMethods/ViewModelExtensionMethods.cs
@@ -35,14 +35,25 @@ public static class ViewModelExtensionMethods
/// <param name="propertyName">The property name.</param>
public static void SetFocus(this ViewModel vm, string propertyName)
{
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
+ Application.Current.Dispatcher.BeginInvoke(new Action(async () =>
{
- var element = FindElementByPropertyName(vm, Application.Current.MainWindow, propertyName);
+ await Task.Delay(200);
- if (element != null)
+ var control = GetUserControl(vm, Application.Current.MainWindow);
+
+ if (control != null)
{
- element.Focusable = true;
- Keyboard.Focus(element);
+ var element = FindElementByPropertyName(vm, control, propertyName);
+
+ if (element != null)
+ {
+ element.Focusable = true;
+ Keyboard.Focus(element);
+ }
+ else
+ {
+ Debug.WriteLine($"SetFocus: {propertyName} not found!");
+ }
}
else
{
@@ -52,7 +63,31 @@ public static class ViewModelExtensionMethods
}), DispatcherPriority.ApplicationIdle);
}
- private static FrameworkElement FindElementByPropertyName(ViewModel vm, UIElement parent, string propName)
+ private static UserControl GetUserControl(ViewModel vm, FrameworkElement parent)
+ {
+ var children = parent.FindVisualChildren<UserControl>();
+
+ foreach (var child in children)
+ {
+ if (child.DataContext == vm)
+ {
+ return child;
+ }
+ else
+ {
+ var innerChild = GetUserControl(vm, child);
+
+ if (innerChild != null)
+ {
+ return innerChild;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private static FrameworkElement FindElementByPropertyName(ViewModel vm, FrameworkElement parent, string propName)
{
FrameworkElement foundChild = null;