2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// TextControl.xaml 的交互逻辑
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class TextControl : UserControl
|
|
|
|
|
|
{
|
2023-01-27 20:10:17 +08:00
|
|
|
|
//public static readonly DependencyProperty DoubleEditProperty = DependencyProperty.Register(
|
|
|
|
|
|
// nameof(DoubleEdit), typeof(bool), typeof(TextControl), new FrameworkPropertyMetadata(
|
|
|
|
|
|
// true));
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
2023-01-27 20:10:17 +08:00
|
|
|
|
//public bool DoubleEdit
|
|
|
|
|
|
//{
|
|
|
|
|
|
// get => (bool)GetValue(DoubleEditProperty);
|
|
|
|
|
|
// set => SetValue(DoubleEditProperty, value);
|
|
|
|
|
|
//}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
|
|
|
|
|
|
public TextControl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
|
|
this.Loaded += TextControl_Loaded;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void TextControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Loaded -= TextControl_Loaded;
|
|
|
|
|
|
|
|
|
|
|
|
PART_ShowText.Visibility = Visibility.Visible;
|
|
|
|
|
|
PART_TextBlock.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
PART_ShowText.Focus();
|
|
|
|
|
|
if (!string.IsNullOrEmpty(PART_ShowText.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
PART_ShowText.SelectionStart = PART_ShowText.Text.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-22 21:46:59 +08:00
|
|
|
|
if (this.DataContext is ISelectable selectable)
|
|
|
|
|
|
{
|
2023-01-23 22:05:51 +08:00
|
|
|
|
selectable.PropertyChanged -= TextControl_PropertyChanged;
|
2023-01-22 21:46:59 +08:00
|
|
|
|
selectable.PropertyChanged += TextControl_PropertyChanged;
|
|
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
TextControl_PropertyChanged(this.DataContext, new System.ComponentModel.PropertyChangedEventArgs("IsSelected"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void TextControl_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.PropertyName == "IsSelected")
|
|
|
|
|
|
{
|
2023-01-22 21:46:59 +08:00
|
|
|
|
if (sender is ISelectable selectable)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2023-01-22 21:46:59 +08:00
|
|
|
|
if (selectable.IsSelected == false)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
PART_ShowText.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
PART_TextBlock.Visibility = Visibility.Visible;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-01-27 20:10:17 +08:00
|
|
|
|
else if (e.PropertyName == "EditText")
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
PART_ShowText.Visibility = Visibility.Visible;
|
|
|
|
|
|
PART_TextBlock.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
PART_ShowText.Focus();
|
|
|
|
|
|
if (!string.IsNullOrEmpty(PART_ShowText.Text))
|
|
|
|
|
|
{
|
|
|
|
|
|
PART_ShowText.SelectionStart = PART_ShowText.Text.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-27 20:10:17 +08:00
|
|
|
|
//protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// base.OnPreviewMouseDown(e);
|
|
|
|
|
|
|
|
|
|
|
|
// if (DoubleEdit == false)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// PART_ShowText.Visibility = Visibility.Visible;
|
|
|
|
|
|
// PART_TextBlock.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
// PART_ShowText.Focus();
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(PART_ShowText.Text))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// PART_ShowText.SelectionStart = PART_ShowText.Text.Length;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//protected override void OnPreviewMouseDoubleClick(MouseButtonEventArgs e)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// base.OnPreviewMouseDoubleClick(e);
|
|
|
|
|
|
|
|
|
|
|
|
// if (DoubleEdit == true)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// PART_ShowText.Visibility = Visibility.Visible;
|
|
|
|
|
|
// PART_TextBlock.Visibility = Visibility.Collapsed;
|
|
|
|
|
|
// PART_ShowText.Focus();
|
|
|
|
|
|
// if (!string.IsNullOrEmpty(PART_ShowText.Text))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// PART_ShowText.SelectionStart = PART_ShowText.Text.Length;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class ControlAttachProperty
|
|
|
|
|
|
{
|
|
|
|
|
|
#region WatermarkProperty 水印
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 水印
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"Watermark", typeof(string), typeof(ControlAttachProperty), new FrameworkPropertyMetadata(""));
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetWatermark(DependencyObject d)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (string)d.GetValue(WatermarkProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void SetWatermark(DependencyObject obj, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.SetValue(WatermarkProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|