在Windows应用商店应用(XAML/C#)中,我创建了一个带有'RichEditBox'的自定义控件。我想限制它的字符数(MaxLength),或者至少应该禁用垂直滚动条。我怎样才能实现它?WinRT RichEditBox局限性
0
A
回答
0
我认为不可能以声明方式设置字符数限制,但是您可以处理文本更改的事件并在代码后面执行代码检查。
对于滚轮可以将ScrollViewer.VerticalScrollBarVisibility
属性设置为Disabled
。
0
这里尝试了这一点:
<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;
更多的代码背后:
私人无效TextElementControlTextChanged(对象发件人, RoutedEventArgs E) { 字符串str; TextElementControl.Document.GetText(Windows.UI.Text.TextGetOptions.None, out str); TextElementControl.Height = double.NaN;
if (str.Trim().Length > 502 && !_loading) { if (popUpReminder == null) { popUpReminder = new Popup(); popUpReminder.IsLightDismissEnabled = true; var panel = new StackPanel(); panel.Background = BlackSolidColorBrush; panel.Height = 60; panel.Width = 220; var reminderText = new TextBlock(); reminderText.FontSize = 14; reminderText.Text = "You have exceeded the maximum number of characters for this textbox."; reminderText.TextWrapping = TextWrapping.Wrap; reminderText.Focus(Windows.UI.Xaml.FocusState.Programmatic); reminderText.Margin = new Thickness(10, 5, 10, 5); panel.Children.Add(reminderText); Border brder = new Border(); brder.BorderBrush = RedSolidColorBrush; brder.BorderThickness = new Thickness(2); brder.Child = panel; popUpReminder.Child = brder; popUpReminder.HorizontalOffset = Window.Current.CoreWindow.Bounds.Width - panel.Width - 10; popUpReminder.VerticalOffset = Window.Current.CoreWindow.Bounds.Bottom - 100 - panel.Height - 10; } popUpReminder.IsOpen = true; TextElementControl.Document.Undo(); } }
相关问题
- 1. WinRT RichEditBox内容为HTML文本
- 2. XAML喷吹成RichEditBox
- 3. Settings.bundle局限性
- 4. document.referrer - 局限性?
- 5. UWP/WinRT:如何滚动RichEditBox到光标位置?
- 6. WinRt:如何添加和删除RichEditBox上的链接?
- 7. 如何完全清除/设置WinRT的RichEditBox文本?
- 8. sharpDevelop的局限性
- 9. GL_DOT3_RGB的局限性
- 10. Swing的局限性
- 11. Android的局限性
- 12. Powerapps SQL局限性
- 13. beforeRouteLeave的局限性?
- 14. Redis MGET局限性
- 15. eval()的局限性?
- 16. MongoDB的局限性?
- 17. ffmpeg的局限性?
- 18. WinRT应用程序
- 19. WinRT CheckBox属性
- 20. DynamoDB与Cognito的局限性
- 21. 子类的局限性OOP
- 22. Pgrouting - pgr_kdijkstraCost int局限性
- 23. WebApp的APEX的局限性
- 24. 用法和局限性5
- 25. zedgraphweb中的局限性
- 26. 使用@ Html.EditorForModel的局限性
- 27. wordpress的缺点/局限性?
- 28. MySQL JDBC的局限性
- 29. QProcess局限性帮助
- 30. 如何在WinRT/UWP RichEditBox中保持突出显示的文字焦点丢失?