From fb3abe8ee422deb6e0221915ee2d170e7fd2570c Mon Sep 17 00:00:00 2001
From: omidmohajers <120931404+omidmohajers@users.noreply.github.com>
Date: Wed, 25 Jan 2023 22:40:51 +0330
Subject: [PATCH] remove duplicate code on ipfield events and change key
navigation behavior
---
IPUserControls/IpField.xaml | 22 ++++++----
IPUserControls/IpField.xaml.cs | 38 +++++++++++-----
.../Properties/Resources.Designer.cs | 44 ++++++++-----------
.../Properties/Settings.Designer.cs | 22 ++++------
Prototyping Prism/Prototyping Prism.csproj | 4 +-
Prototyping Prism/app.config | 3 ++
Prototyping/App.config | 6 +--
Prototyping/MainWindow.xaml | 6 ++-
Prototyping/MainWindow.xaml.cs | 4 +-
Prototyping/Properties/Resources.Designer.cs | 43 ++++++++----------
Prototyping/Properties/Settings.Designer.cs | 21 ++++-----
Prototyping/Prototyping.csproj | 3 +-
12 files changed, 112 insertions(+), 104 deletions(-)
create mode 100644 Prototyping Prism/app.config
diff --git a/IPUserControls/IpField.xaml b/IPUserControls/IpField.xaml
index e983c72..5848d92 100644
--- a/IPUserControls/IpField.xaml
+++ b/IPUserControls/IpField.xaml
@@ -33,8 +33,9 @@
BorderThickness="0"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
- GotKeyboardFocus="FirstByteTextBox_GotKeyboardFocus"
- PreviewKeyDown="FirstByteTextBox_OnPreviewKeyDown"/>
+ TextChanged="TextChanged"
+ GotKeyboardFocus="OnGotKeyboardFocus"
+ PreviewKeyDown="OnPreviewKeyDown"/>
+ TextChanged="TextChanged"
+ GotKeyboardFocus="OnGotKeyboardFocus"
+ PreviewKeyDown="OnPreviewKeyDown"/>
+ TextChanged="TextChanged"
+ GotKeyboardFocus="OnGotKeyboardFocus"
+ PreviewKeyDown="OnPreviewKeyDown"/>
-
+ TextChanged="TextChanged"
+ GotKeyboardFocus="OnGotKeyboardFocus"
+ PreviewKeyDown="OnPreviewKeyDown"/>
+
diff --git a/IPUserControls/IpField.xaml.cs b/IPUserControls/IpField.xaml.cs
index f429b5e..f184909 100644
--- a/IPUserControls/IpField.xaml.cs
+++ b/IPUserControls/IpField.xaml.cs
@@ -125,8 +125,10 @@ private void SetIpByteProperty(ref string backingField, string value, string pro
// Handles valid byte-input
else if (value.IsByte())
+ {
backingField = value;
-
+ }
+
// Is number but not a byte
else
return;
@@ -205,16 +207,10 @@ public string IpFourthByte
#region Events
// Select All Text On Keyboard Focus
- private void FirstByteTextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) => FirstByteTextBox.SelectAll();
- private void SecondByteTextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) => SecondByteTextBox.SelectAll();
- private void ThirdByteTextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) => ThirdByteTextBox.SelectAll();
- private void FourthByteTextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) => FourthByteTextBox.SelectAll();
+ private void OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) => (sender as TextBox).SelectAll();
// Shift text box focus on key down events
- private void FirstByteTextBox_OnPreviewKeyDown(object sender, KeyEventArgs e) => ShiftTextBoxFocus((TextBox)sender, e);
- private void SecondByteTextBox_OnPreviewKeyDown(object sender, KeyEventArgs e) => ShiftTextBoxFocus((TextBox)sender, e);
- private void ThirdByteTextBox_OnPreviewKeyDown(object sender, KeyEventArgs e) => ShiftTextBoxFocus((TextBox)sender, e);
- private void FourthByteTextBox_OnPreviewKeyDown(object sender, KeyEventArgs e) => ShiftTextBoxFocus((TextBox)sender, e);
+ private void OnPreviewKeyDown(object sender, KeyEventArgs e) => ShiftTextBoxFocus((TextBox)sender, e);
private static void ShiftTextBoxFocus (TextBox textBox, KeyEventArgs e)
{
@@ -233,14 +229,34 @@ private static void ShiftTextBoxFocus (TextBox textBox, KeyEventArgs e)
break;
}
case Key.Back:
+ if (textBox.SelectedText.Length != textBox.Text.Length)
+ {
+ if (textBox.CaretIndex == 0)
+ textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
+ }
+ else
+ {
+ textBox.Text = string.Empty;
+ }
+ break;
case Key.Left:
{
- if (textBox.CaretIndex == 0)
- textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
+ if (textBox.CaretIndex == 0)
+ textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
break;
}
}
}
+ private void TextChanged(object sender, TextChangedEventArgs e)
+ {
+ TextBox textBox = sender as TextBox;
+ if (textBox.Text.Length == 3)
+ {
+ textBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
+ if (textBox.Text == "0")
+ textBox.Text = "";
+ }
+ }
#endregion Events
#region Property Notifications
diff --git a/Prototyping Prism/Properties/Resources.Designer.cs b/Prototyping Prism/Properties/Resources.Designer.cs
index 77a6465..d74778f 100644
--- a/Prototyping Prism/Properties/Resources.Designer.cs
+++ b/Prototyping Prism/Properties/Resources.Designer.cs
@@ -8,10 +8,10 @@
//
//------------------------------------------------------------------------------
-namespace Prototyping_Prism.Properties
-{
-
-
+namespace Prototyping_Prism.Properties {
+ using System;
+
+
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
@@ -19,51 +19,43 @@ namespace Prototyping_Prism.Properties
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources
- {
-
+ internal class Resources {
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources()
- {
+ internal Resources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager
- {
- get
- {
- if ((resourceMan == null))
- {
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Prototyping_Prism.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture
- {
- get
- {
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
return resourceCulture;
}
- set
- {
+ set {
resourceCulture = value;
}
}
diff --git a/Prototyping Prism/Properties/Settings.Designer.cs b/Prototyping Prism/Properties/Settings.Designer.cs
index fd9efb3..edab828 100644
--- a/Prototyping Prism/Properties/Settings.Designer.cs
+++ b/Prototyping Prism/Properties/Settings.Designer.cs
@@ -8,21 +8,17 @@
//
//------------------------------------------------------------------------------
-namespace Prototyping_Prism.Properties
-{
-
-
+namespace Prototyping_Prism.Properties {
+
+
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
+
+ public static Settings Default {
+ get {
return defaultInstance;
}
}
diff --git a/Prototyping Prism/Prototyping Prism.csproj b/Prototyping Prism/Prototyping Prism.csproj
index 823af39..169a60f 100644
--- a/Prototyping Prism/Prototyping Prism.csproj
+++ b/Prototyping Prism/Prototyping Prism.csproj
@@ -9,12 +9,13 @@
Properties
Prototyping_Prism
Prototyping Prism
- v4.8
+ v4.6.1
512
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
4
true
PackageReference
+
AnyCPU
@@ -88,6 +89,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/Prototyping Prism/app.config b/Prototyping Prism/app.config
new file mode 100644
index 0000000..3dbff35
--- /dev/null
+++ b/Prototyping Prism/app.config
@@ -0,0 +1,3 @@
+
+
+
diff --git a/Prototyping/App.config b/Prototyping/App.config
index 193aecc..bae5d6d 100644
--- a/Prototyping/App.config
+++ b/Prototyping/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/Prototyping/MainWindow.xaml b/Prototyping/MainWindow.xaml
index 4e301fb..2fa0419 100644
--- a/Prototyping/MainWindow.xaml
+++ b/Prototyping/MainWindow.xaml
@@ -7,13 +7,13 @@
xmlns:vm ="clr-namespace:Prototyping"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d"
- Title="Test Window" Height="133.733" Width="395.733">
+ Title="Test Window" Height="188.37" Width="395.733">
-
+
@@ -28,6 +28,8 @@
+
+
\ No newline at end of file
diff --git a/Prototyping/MainWindow.xaml.cs b/Prototyping/MainWindow.xaml.cs
index 55b6abb..e411217 100644
--- a/Prototyping/MainWindow.xaml.cs
+++ b/Prototyping/MainWindow.xaml.cs
@@ -13,11 +13,13 @@ public partial class MainWindow : INotifyPropertyChanged
{
public MainWindow()
{
+ IpAddress = "127.0.0.1";
InitializeComponent();
}
-
+ public string IpAddress { get; set; }
private void Button_Click(object sender, RoutedEventArgs e)
{
+ MessageBox.Show(IpAddress);
if (IpStatus.ConnectionStatus != ConnectionStatus.Connected)
Connect();
else
diff --git a/Prototyping/Properties/Resources.Designer.cs b/Prototyping/Properties/Resources.Designer.cs
index 5d69932..ff618f4 100644
--- a/Prototyping/Properties/Resources.Designer.cs
+++ b/Prototyping/Properties/Resources.Designer.cs
@@ -8,9 +8,10 @@
//
//------------------------------------------------------------------------------
-
-namespace Prototyping.Properties
-{
+namespace Prototyping.Properties {
+ using System;
+
+
///
/// A strongly-typed resource class, for looking up localized strings, etc.
///
@@ -18,51 +19,43 @@ namespace Prototyping.Properties
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class Resources
- {
-
+ internal class Resources {
+
private static global::System.Resources.ResourceManager resourceMan;
-
+
private static global::System.Globalization.CultureInfo resourceCulture;
-
+
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal Resources()
- {
+ internal Resources() {
}
-
+
///
/// Returns the cached ResourceManager instance used by this class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager
- {
- get
- {
- if ((resourceMan == null))
- {
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Prototyping.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
-
+
///
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture
- {
- get
- {
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
return resourceCulture;
}
- set
- {
+ set {
resourceCulture = value;
}
}
diff --git a/Prototyping/Properties/Settings.Designer.cs b/Prototyping/Properties/Settings.Designer.cs
index 15c2752..d9ecd60 100644
--- a/Prototyping/Properties/Settings.Designer.cs
+++ b/Prototyping/Properties/Settings.Designer.cs
@@ -8,20 +8,17 @@
//
//------------------------------------------------------------------------------
-
-namespace Prototyping.Properties
-{
+namespace Prototyping.Properties {
+
+
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
- {
-
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default
- {
- get
- {
+
+ public static Settings Default {
+ get {
return defaultInstance;
}
}
diff --git a/Prototyping/Prototyping.csproj b/Prototyping/Prototyping.csproj
index 11a7465..11e124c 100644
--- a/Prototyping/Prototyping.csproj
+++ b/Prototyping/Prototyping.csproj
@@ -8,12 +8,13 @@
WinExe
Prototyping
Prototyping
- v4.8
+ v4.6.1
512
{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
4
true
true
+
AnyCPU