using NaiBa.Util.Extension; using System; using System.Collections.Generic; using System.Drawing.Drawing2D; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; 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; using static System.Net.Mime.MediaTypeNames; namespace _29WxOrderWpf.UserControls { /// /// UcWaterMarkTextBox.xaml 的交互逻辑 /// public partial class UcWaterMarkTextBox : UserControl { public event Action TextChanged; public UcWaterMarkTextBox() { InitializeComponent(); DataContext = this; //this.txt.TextChanged } public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(UcWaterMarkTextBox), null); public string Text { get { return (string)GetValue(TextProperty) == null ? "" : (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public static readonly DependencyProperty WaterMarkProperty = DependencyProperty.Register("WaterMark", typeof(string), typeof(UcWaterMarkTextBox), null); public string WaterMark { get { return (string)GetValue(WaterMarkProperty) == null ? "" : (string)GetValue(WaterMarkProperty); } set { SetValue(WaterMarkProperty, value); } } public static readonly DependencyProperty TextWrappingProperty = DependencyProperty.Register("TextWrapping", typeof(TextWrapping), typeof(UcWaterMarkTextBox), null); public TextWrapping TextWrapping { get { return (TextWrapping)GetValue(TextWrappingProperty); } set { SetValue(TextWrappingProperty, value); } } public static readonly DependencyProperty TextBorderThicknessProperty = DependencyProperty.Register("TextBorderThickness", typeof(Thickness), typeof(UcWaterMarkTextBox), new PropertyMetadata(new Thickness(1))); public Thickness TextBorderThickness { get { return (Thickness)GetValue(TextBorderThicknessProperty); } set { SetValue(TextBorderThicknessProperty, value); } } private void txt_TextChanged(object sender, TextChangedEventArgs e) { this.Text = txt.Text; TextChanged?.Invoke(this, e); } } public class WaterMarkVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return value.ParseToString().IsNullOrEmpty() ? Visibility.Visible : Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); // 单向绑定可不实现 } } }