From 6651dfb381a69df392533e617e5d9b1393650e6b Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Fri, 14 Apr 2023 09:32:43 +0200 Subject: [PATCH] added and included MultiFormatTextBox in SendReceiveView --- .../ExtendedTabControl/ExtendedTabControl.cs | 124 +++++++++--------- .../MultiFormatTextBox/MultiFormatTextBox.cs | 41 ++++++ .../MultiFormatTextBox.xaml | 56 ++++++++ .../Themes/Generic.xaml | 3 +- MultiTerm.Wpf/View/SendReceiveView.xaml | 23 +++- 5 files changed, 181 insertions(+), 66 deletions(-) create mode 100644 MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs create mode 100644 MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.xaml diff --git a/MultiTerm.Wpf.CustomControl/ExtendedTabControl/ExtendedTabControl.cs b/MultiTerm.Wpf.CustomControl/ExtendedTabControl/ExtendedTabControl.cs index c1bdf27..80e327e 100644 --- a/MultiTerm.Wpf.CustomControl/ExtendedTabControl/ExtendedTabControl.cs +++ b/MultiTerm.Wpf.CustomControl/ExtendedTabControl/ExtendedTabControl.cs @@ -1,78 +1,76 @@ -using System.Runtime.CompilerServices; -using System.Windows; +using System.Windows; using System.Windows.Controls; -namespace MultiTerm.Wpf.CustomControl +namespace MultiTerm.Wpf.CustomControl; + +/// +/// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file. +/// +/// Step 1a) Using this custom control in a XAML file that exists in the current project. +/// Add this XmlNamespace attribute to the root element of the markup file where it is +/// to be used: +/// +/// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.Controls" +/// +/// +/// Step 1b) Using this custom control in a XAML file that exists in a different project. +/// Add this XmlNamespace attribute to the root element of the markup file where it is +/// to be used: +/// +/// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.Controls;assembly=MultiTerm.Wpf.Controls" +/// +/// You will also need to add a project reference from the project where the XAML file lives +/// to this project and Rebuild to avoid compilation errors: +/// +/// Right click on the target project in the Solution Explorer and +/// "Add Reference"->"Projects"->[Browse to and select this project] +/// +/// +/// Step 2) +/// Go ahead and use your control in the XAML file. +/// +/// +/// +/// +public class ExtendedTabControl : TabControl { + public static readonly RoutedEvent AddButtonClickedEvent; + + #region Dotnet Properties /// - /// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file. - /// - /// Step 1a) Using this custom control in a XAML file that exists in the current project. - /// Add this XmlNamespace attribute to the root element of the markup file where it is - /// to be used: - /// - /// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.Controls" - /// - /// - /// Step 1b) Using this custom control in a XAML file that exists in a different project. - /// Add this XmlNamespace attribute to the root element of the markup file where it is - /// to be used: - /// - /// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.Controls;assembly=MultiTerm.Wpf.Controls" - /// - /// You will also need to add a project reference from the project where the XAML file lives - /// to this project and Rebuild to avoid compilation errors: - /// - /// Right click on the target project in the Solution Explorer and - /// "Add Reference"->"Projects"->[Browse to and select this project] - /// - /// - /// Step 2) - /// Go ahead and use your control in the XAML file. - /// - /// - /// + /// .NET Property for /// - public class ExtendedTabControl : TabControl + public event RoutedEventHandler AddButtonClicked { - public static readonly RoutedEvent AddButtonClickedEvent; + add { this.AddHandler(AddButtonClickedEvent, value); } + remove { this.RemoveHandler(AddButtonClickedEvent, value); } + } + #endregion - #region Dotnet Properties - /// - /// .NET Property for - /// - public event RoutedEventHandler AddButtonClicked - { - add { this.AddHandler(AddButtonClickedEvent, value); } - remove { this.RemoveHandler(AddButtonClickedEvent, value); } - } - #endregion + static ExtendedTabControl() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedTabControl), new FrameworkPropertyMetadata(typeof(ExtendedTabControl))); - static ExtendedTabControl() - { - DefaultStyleKeyProperty.OverrideMetadata(typeof(ExtendedTabControl), new FrameworkPropertyMetadata(typeof(ExtendedTabControl))); + AddButtonClickedEvent = EventManager.RegisterRoutedEvent("AddButtonClicked", + RoutingStrategy.Bubble, typeof(RoutedEventArgs), + typeof(ExtendedTabControl)); + } - AddButtonClickedEvent = EventManager.RegisterRoutedEvent("AddButtonClicked", - RoutingStrategy.Bubble, typeof(RoutedEventArgs), - typeof(ExtendedTabControl)); - } + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); - public override void OnApplyTemplate() + // get button from template + var button = GetTemplateChild("addButton") as Button; + if (button != null) { - base.OnApplyTemplate(); - - // get button from template - var button = GetTemplateChild("addButton") as Button; - if (button != null) - { - button.Click += OnAddButtonClicked; ; - } + button.Click += OnAddButtonClicked; ; } + } - private void OnAddButtonClicked(object sender, RoutedEventArgs e) - { - RoutedEventArgs args = new RoutedEventArgs(AddButtonClickedEvent); - RaiseEvent(args); - } + private void OnAddButtonClicked(object sender, RoutedEventArgs e) + { + RoutedEventArgs args = new RoutedEventArgs(AddButtonClickedEvent); + RaiseEvent(args); } } diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs new file mode 100644 index 0000000..bf0cf9d --- /dev/null +++ b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs @@ -0,0 +1,41 @@ +using System.Windows; +using System.Windows.Controls; + +namespace MultiTerm.Wpf.CustomControl; + +/// +/// Follow steps 1a or 1b and then 2 to use this custom control in a XAML file. +/// +/// Step 1a) Using this custom control in a XAML file that exists in the current project. +/// Add this XmlNamespace attribute to the root element of the markup file where it is +/// to be used: +/// +/// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.CustomControl" +/// +/// +/// Step 1b) Using this custom control in a XAML file that exists in a different project. +/// Add this XmlNamespace attribute to the root element of the markup file where it is +/// to be used: +/// +/// xmlns:MyNamespace="clr-namespace:MultiTerm.Wpf.CustomControl.MultiFormatTextBox;assembly=MultiTerm.Wpf.CustomControl.MultiFormatTextBox" +/// +/// You will also need to add a project reference from the project where the XAML file lives +/// to this project and Rebuild to avoid compilation errors: +/// +/// Right click on the target project in the Solution Explorer and +/// "Add Reference"->"Projects"->[Browse to and select this project] +/// +/// +/// Step 2) +/// Go ahead and use your control in the XAML file. +/// +/// +/// +/// +public class MultiFormatTextBox : TextBox +{ + static MultiFormatTextBox() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(MultiFormatTextBox), new FrameworkPropertyMetadata(typeof(MultiFormatTextBox))); + } +} diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.xaml b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.xaml new file mode 100644 index 0000000..77c27b4 --- /dev/null +++ b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.xaml @@ -0,0 +1,56 @@ + + + + + + + \ No newline at end of file diff --git a/MultiTerm.Wpf.CustomControl/Themes/Generic.xaml b/MultiTerm.Wpf.CustomControl/Themes/Generic.xaml index 7099259..eccd603 100644 --- a/MultiTerm.Wpf.CustomControl/Themes/Generic.xaml +++ b/MultiTerm.Wpf.CustomControl/Themes/Generic.xaml @@ -6,7 +6,8 @@ + - + diff --git a/MultiTerm.Wpf/View/SendReceiveView.xaml b/MultiTerm.Wpf/View/SendReceiveView.xaml index 73e5219..9a70519 100644 --- a/MultiTerm.Wpf/View/SendReceiveView.xaml +++ b/MultiTerm.Wpf/View/SendReceiveView.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:MultiTerm.Wpf.View" xmlns:protocol_serial="clr-namespace:MultiTerm.Protocols.Serial;assembly=MultiTerm.Protocols" xmlns:settings_view="clr-namespace:MultiTerm.Wpf.View.SettingsView" + xmlns:custom_controls="clr-namespace:MultiTerm.Wpf.CustomControl;assembly=MultiTerm.Wpf.CustomControl" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> @@ -14,11 +15,12 @@ - + + - + @@ -28,5 +30,22 @@ + + + + + + + + +