首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WinRT RichEditBox限制

WinRT RichEditBox限制
EN

Stack Overflow用户
提问于 2012-11-19 13:22:28
回答 2查看 908关注 0票数 0

在Windows Store app (XAML/C#)中,我创建了一个带有'RichEditBox‘的自定义控件。我想限制它的字符数(MaxLength),或者至少应该禁用垂直滚动条。我怎样才能做到这一点?

EN

回答 2

Stack Overflow用户

发布于 2013-02-14 22:14:11

我认为以声明的方式设置字符数的限制是不可能的,但您可以处理文本更改事件,并在后面的代码中进行检查。

对于滚动条,可以将ScrollViewer.VerticalScrollBarVisibility属性设置为Disabled

票数 0
EN

Stack Overflow用户

发布于 2013-10-23 16:19:57

在这里试试这个:

代码语言:javascript
复制
<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();} }

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13448116

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档