在Windows Store app (XAML/C#)中,我创建了一个带有'RichEditBox‘的自定义控件。我想限制它的字符数(MaxLength),或者至少应该禁用垂直滚动条。我怎样才能做到这一点?
发布于 2013-02-14 22:14:11
我认为以声明的方式设置字符数的限制是不可能的,但您可以处理文本更改事件,并在后面的代码中进行检查。
对于滚动条,可以将ScrollViewer.VerticalScrollBarVisibility属性设置为Disabled。
发布于 2013-10-23 16:19:57
在这里试试这个:
<RichEditBox x:Name="TextElementControl"
Background="{Binding Background, ElementName=userControlModified}"
ManipulationMode="None"
ScrollViewer.HorizontalScrollMode="Disabled"
AcceptsReturn="True" TextWrapping="Wrap"
SizeChanged="TextElementControlSizeChanged"
IsDoubleTapEnabled="False"
BorderThickness="0"
BorderBrush="{x:Null}"
Padding="10,10,10,10"
/>代码隐藏:
TextElementControl.TextChanged += TextElementControlTextChanged;
更多代码隐藏:
TextElementControl.Document.GetText(Windows.UI.Text.TextGetOptions.None,
TextElementControlTextChanged(对象发送者,RoutedEventArgs e) { string str;RoutedEventArgs out str;TextElementControl.Height = double.NaN;
if (str.Trim().Length > 502 && !_loading) { if (popUpReminder == null) { popUpReminder =新弹出窗口();popUpReminder.IsLightDismissEnabled = true;var StackPanel=新StackPanel();panel.Background = BlackSolidColorBrush;panel.Height = 60;panel.Width = 220;var reminderText = reminderText.Focus(Windows.UI.Xaml.FocusState.Programmatic);TextBlock();reminderText.FontSize = 14;reminderText.Text =“您已超过此文本框的最大字符数。”;reminderText.TextWrapping = TextWrapping.Wrap;var reminderText.Margin =新厚度( 10,5,10,5);边框(ReminderText);边框=新边框();brder.BorderBrush = RedSolidColorBrush;brder.BorderThickness =新厚度(2);brder.Child =面板;popUpReminder.Child =边框;popUpReminder.HorizontalOffset = Window.Current.CoreWindow.Bounds.Width - panel.Width - 10;popUpReminder.VerticalOffset = Window.Current.CoreWindow.Bounds.Bottom - 100 - panel.Height - 10;} popUpReminder.IsOpen =真;TextElementControl.Document.Undo();} }
https://stackoverflow.com/questions/13448116
复制相似问题