replace v6 with experimental v7 code

This commit is contained in:
stax76
2023-10-24 11:17:45 +02:00
parent fb27bb8727
commit 5706d7b66d
212 changed files with 15014 additions and 12173 deletions

View File

@@ -0,0 +1,72 @@

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using MpvNet.Windows.UI;
namespace MpvNet.Windows.WPF.Controls;
public partial class SearchControl : UserControl
{
string? _hintText;
bool _gotFocus;
public bool HideClearButton { get; set; }
public SearchControl() => InitializeComponent();
public Theme? Theme => Theme.Current;
public string HintText {
get => _hintText ??= "";
set {
_hintText = value;
UpdateControls();
}
}
[RelayCommand]
void Clear()
{
Text = "";
Keyboard.Focus(SearchTextBox);
}
void UpdateControls()
{
HintTextBlock.Text = Text == "" ? HintText : "";
if (Text == "" || HideClearButton)
SearchClearButton.Visibility = Visibility.Hidden;
else
SearchClearButton.Visibility = Visibility.Visible;
}
public string Text
{
get => (string)GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string),
typeof(SearchControl), new PropertyMetadata(OnCustomerChangedCallBack));
static void OnCustomerChangedCallBack(
DependencyObject sender, DependencyPropertyChangedEventArgs e) =>
(sender as SearchControl)?.UpdateControls();
void SearchTextBox_GotFocus(object sender, RoutedEventArgs e) => _gotFocus = true;
void SearchTextBox_PreviewMouseUp(object sender, MouseButtonEventArgs e)
{
if (_gotFocus)
{
SearchTextBox?.SelectAll();
_gotFocus = false;
}
}
}