Csharp/C#教程:使用MahApps保持样式在WPF中扩展TextBox分享


使用MahApps保持样式在WPF中扩展TextBox

我创建了一个自定义文本框类,用于validation用户的输入以仅允许hex值,并在xaml中使用此新文本框(HexTextBox)。 它运行良好,但HexTextBox丢失了Mahapps的所有样式,包括配色方案和TextBoxHelper。 你知道如何使用这个扩展的TexBox并保持风格吗?

HexTextBox:

public class HexTextBox : TextBox { public HexTextBox() { } ///  /// Raise when a keyboard key is pressed. ///  /// The event args. protected override void OnPreviewKeyDown(KeyEventArgs e) { if (e.Key == Key.Space) { e.Handled = true; } base.OnPreviewKeyDown(e); } ///  /// Raise when a text will be inputed in the text box object. ///  /// The event args. protected override void OnTextInput(TextCompositionEventArgs e) { int hexNumber; e.Handled = !int.TryParse(e.Text, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out hexNumber); base.OnTextInput(e); } } 

Window.xaml

   

提前致谢!

为自定义控件创建默认样式,该样式将基于TextBox样式。

上述就是C#学习教程:使用MahApps保持样式在WPF中扩展TextBox分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1026752.html

(0)
上一篇 2022年1月9日
下一篇 2022年1月9日

精彩推荐