mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Setting Find Changes
- added a find window to find setting in the settings control.
This commit is contained in:
parent
174b5f14c9
commit
46997c6e71
18 changed files with 774 additions and 263 deletions
|
|
@ -31,6 +31,7 @@ namespace ServerManagerTool.Common.Controls
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Focusable = true;
|
||||
Value = new NullableValue<float>();
|
||||
|
||||
(this.Content as FrameworkElement).DataContext = this;
|
||||
|
|
@ -148,5 +149,13 @@ namespace ServerManagerTool.Common.Controls
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new bool Focus()
|
||||
{
|
||||
if (this.CheckBox.IsChecked ?? false == true)
|
||||
return Slider.Focus();
|
||||
else
|
||||
return this.CheckBox.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace ServerManagerTool.Common.Controls
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Focusable = true;
|
||||
Value = new NullableValue<int>();
|
||||
|
||||
(this.Content as FrameworkElement).DataContext = this;
|
||||
|
|
@ -148,5 +149,13 @@ namespace ServerManagerTool.Common.Controls
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new bool Focus()
|
||||
{
|
||||
if (this.CheckBox.IsChecked ?? false == true)
|
||||
return Slider.Focus();
|
||||
else
|
||||
return this.CheckBox.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ namespace ServerManagerTool.Common.Controls
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Focusable = true;
|
||||
Value = new NullableValue<long>();
|
||||
|
||||
(this.Content as FrameworkElement).DataContext = this;
|
||||
|
|
@ -148,5 +149,13 @@ namespace ServerManagerTool.Common.Controls
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new bool Focus()
|
||||
{
|
||||
if (this.CheckBox.IsChecked ?? false == true)
|
||||
return Slider.Focus();
|
||||
else
|
||||
return this.CheckBox.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,15 @@ namespace ServerManagerTool.Common.Controls
|
|||
public static readonly DependencyProperty SuffixRelativeWidthProperty = DependencyProperty.Register(nameof(SuffixRelativeWidth), typeof(string), typeof(AnnotatedSlider), new PropertyMetadata("1*"));
|
||||
public static readonly DependencyProperty SuffixRelativeMinWidthProperty = DependencyProperty.Register(nameof(SuffixRelativeMinWidth), typeof(string), typeof(AnnotatedSlider), new PropertyMetadata("0"));
|
||||
|
||||
public AnnotatedSlider()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Focusable = true;
|
||||
|
||||
(this.Content as FrameworkElement).DataContext = this;
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get { return (string)GetValue(LabelProperty); }
|
||||
|
|
@ -128,12 +137,6 @@ namespace ServerManagerTool.Common.Controls
|
|||
set { SetValue(SuffixRelativeMinWidthProperty, value); }
|
||||
}
|
||||
|
||||
public AnnotatedSlider()
|
||||
{
|
||||
InitializeComponent();
|
||||
(this.Content as FrameworkElement).DataContext = this;
|
||||
}
|
||||
|
||||
private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
|
||||
{
|
||||
if(Slider.IsFocused)
|
||||
|
|
@ -144,5 +147,10 @@ namespace ServerManagerTool.Common.Controls
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public new bool Focus()
|
||||
{
|
||||
return Slider.Focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
19
src/ServerManager.Common/Controls/CheckBoxAndTextBlock.xaml
Normal file
19
src/ServerManager.Common/Controls/CheckBoxAndTextBlock.xaml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<UserControl x:Class="ServerManagerTool.Common.Controls.CheckBoxAndTextBlock"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="300"
|
||||
d:DesignHeight="15"
|
||||
x:Name="Control">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<CheckBox x:Name="CheckBox" Grid.Column="0" Margin="0,0,0,0" IsChecked="{Binding IsChecked, ElementName=Control, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="Label" Grid.Column="1" Margin="5,0,0,0" Text="{Binding Text, ElementName=Control, Mode=TwoWay}" VerticalAlignment="Center" MouseLeftButtonDown="Label_MouseLeftButtonDown"/>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace ServerManagerTool.Common.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CheckBoxAndTextBlock.xaml
|
||||
/// </summary>
|
||||
public partial class CheckBoxAndTextBlock : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(nameof(IsChecked), typeof(bool), typeof(CheckBoxAndTextBlock));
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(CheckBoxAndTextBlock));
|
||||
|
||||
public CheckBoxAndTextBlock()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Focusable = true;
|
||||
|
||||
(this.Content as FrameworkElement).DataContext = this;
|
||||
}
|
||||
|
||||
public bool IsChecked
|
||||
{
|
||||
get { return (bool)GetValue(IsCheckedProperty); }
|
||||
set { SetValue(IsCheckedProperty, value); }
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get { return (string)GetValue(TextProperty); }
|
||||
set { SetValue(TextProperty, value); }
|
||||
}
|
||||
|
||||
public new bool Focus()
|
||||
{
|
||||
return CheckBox.Focus();
|
||||
}
|
||||
|
||||
private void Label_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
if (this.IsEnabled && this.CheckBox.IsEnabled)
|
||||
{
|
||||
this.IsChecked = !this.IsChecked;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/ServerManager.Common/Extensions/StringExtensions.cs
Normal file
17
src/ServerManager.Common/Extensions/StringExtensions.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
namespace ServerManagerTool.Common.Extensions
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool Contains(this string value, string substring, StringComparison comparisonType)
|
||||
{
|
||||
if (substring == null)
|
||||
throw new ArgumentNullException(nameof(substring), $"{nameof(substring)} cannot be null.");
|
||||
if (!Enum.IsDefined(typeof(StringComparison), comparisonType))
|
||||
throw new ArgumentException($"{nameof(comparisonType)} is not a member of StringComparison", nameof(comparisonType));
|
||||
|
||||
return value.IndexOf(substring, comparisonType) >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Controls\AnnotatedCheckBoxAndLongSlider.xaml" />
|
||||
<None Remove="Controls\CheckBoxAndTextBlock.xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNetZip" Version="1.13.8" />
|
||||
|
|
@ -30,6 +31,10 @@
|
|||
</Page>
|
||||
<Page Include="Controls\AnnotatedCheckBoxAndIntegerSlider.xaml" />
|
||||
<Page Include="Controls\AnnotatedSlider.xaml" />
|
||||
<Page Include="Controls\CheckBoxAndTextBlock.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NeXtVdf\NeXt.Vdf.csproj" />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
using System.Linq;
|
||||
using ServerManagerTool.Common.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
|
@ -66,10 +69,11 @@ namespace ServerManagerTool.Common.Utils
|
|||
{
|
||||
if (child == null) return null;
|
||||
var contentElement = child as ContentElement;
|
||||
DependencyObject parent = null;
|
||||
|
||||
if (contentElement != null)
|
||||
{
|
||||
var parent = ContentOperations.GetParent(contentElement);
|
||||
parent = ContentOperations.GetParent(contentElement);
|
||||
if (parent != null) return parent;
|
||||
|
||||
var fce = contentElement as FrameworkContentElement;
|
||||
|
|
@ -77,7 +81,10 @@ namespace ServerManagerTool.Common.Utils
|
|||
}
|
||||
|
||||
//if it's not a ContentElement, rely on VisualTreeHelper
|
||||
return VisualTreeHelper.GetParent(child);
|
||||
parent = VisualTreeHelper.GetParent(child);
|
||||
if (parent is null)
|
||||
parent = LogicalTreeHelper.GetParent(child);
|
||||
return parent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -118,5 +125,48 @@ namespace ServerManagerTool.Common.Utils
|
|||
if (element is T) return (T)element;
|
||||
return TryFindParent<T>(element);
|
||||
}
|
||||
|
||||
private static Dictionary<string, DependencyProperty> BindingProperties = new Dictionary<string, DependencyProperty>
|
||||
{
|
||||
{ "System.Windows.Controls.CheckBox", CheckBox.IsCheckedProperty },
|
||||
{ "System.Windows.Controls.ComboBox", ComboBox.ItemsSourceProperty },
|
||||
{ "System.Windows.Controls.TextBox", TextBox.TextProperty },
|
||||
{ "System.Windows.Controls.Slider", Slider.ValueProperty },
|
||||
{ "System.Windows.Controls.DataGrid", DataGrid.ItemsSourceProperty },
|
||||
{ "ServerManagerTool.Common.Controls.AnnotatedSlider", AnnotatedSlider.ValueProperty },
|
||||
{ "ServerManagerTool.Common.Controls.AnnotatedCheckBoxAndFloatSlider", AnnotatedCheckBoxAndFloatSlider.ValueProperty },
|
||||
{ "ServerManagerTool.Common.Controls.AnnotatedCheckBoxAndIntegerSlider", AnnotatedCheckBoxAndIntegerSlider.ValueProperty },
|
||||
{ "ServerManagerTool.Common.Controls.AnnotatedCheckBoxAndLongSlider", AnnotatedCheckBoxAndLongSlider.ValueProperty },
|
||||
{ "ServerManagerTool.Common.Controls.CheckBoxAndTextBlock", CheckBoxAndTextBlock.IsCheckedProperty },
|
||||
};
|
||||
|
||||
public static List<(string setting, Control control)> GetLogicalTreeControls(DependencyObject parent)
|
||||
{
|
||||
var results = new List<(string setting, Control control)>();
|
||||
|
||||
var children = LogicalTreeHelper.GetChildren(parent).OfType<DependencyObject>();
|
||||
foreach (var child in children)
|
||||
{
|
||||
var recurse = true;
|
||||
if (child is Visual childControl)
|
||||
{
|
||||
var bindingProperty = BindingProperties.FirstOrDefault(b => b.Key.Equals(childControl.GetType().FullName)).Value;
|
||||
if (bindingProperty != null)
|
||||
{
|
||||
var binding = BindingOperations.GetBinding(childControl, bindingProperty);
|
||||
if (binding != null)
|
||||
{
|
||||
results.Add((binding.Path.Path, child as Control));
|
||||
recurse = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recurse)
|
||||
results.AddRange(GetLogicalTreeControls(child));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue