TextBox 上的 MinLines 和 MaxLines 不起作用 [英] MinLines and MaxLines on TextBox not working
本文介绍了TextBox 上的 MinLines 和 MaxLines 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能解释为什么下面的 TextBox 最初没有显示为 3 行高?它显示 1 行高,然后在我开始输入文本时调整为 3.
Can anyone explain why the following TextBox doesn't initially display as 3 lines high? It displays 1 line high and then adjusts to 3 when I start typing text.
这里还有一些表格
<Window x:Class="MyNamespace.Views.DetailsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:MV="clr-namespace:MyNamespace.Views"
xmlns:prop="clr-namespace:MyNamespace.Properties"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
MV:DialogCloser.DialogResult="{Binding Path=DialogResult, Mode=TwoWay}"
Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}"
Title="{Binding Source={x:Static prop:Resources.MyView_Caption}}"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterScreen"
WindowStyle="SingleBorderWindow"
MinHeight="100"
MinWidth="250">
<StackPanel Name="AllItems" Orientation="Horizontal">
<StackPanel Width="450" Margin="5">
<StackPanel Margin="5,0,5,0" VerticalAlignment="Center">
<DockPanel Margin="5" >
<Label Content="Prompt"/>
<TextBox MaxLines="3"
MinLines="3"
VerticalScrollBarVisibility="Auto"
TextWrapping="Wrap" />
</DockPanel>
</StackPanel>
</StackPanel>
</StackPanel>
...
</Window>
推荐答案
是的,我也遇到过这个问题.TextBox 最初在启动时不会正确调整大小,您可以通过将 Text 属性与启动文本绑定来解决此问题(比如一个空白空间值").
Yes, i have too faced this problem. The TextBox will not initially be sized properly at startup and you can workaround this by binding the Text property with an startup text(Say a balnk space value " ").
XAML:
<StackPanel Margin="5,0,5,0" VerticalAlignment="Center">
<DockPanel Margin="5" >
<Label Content="Prompt"/>
<TextBox MaxLines="3"
MinLines="3" x:Name="text"
VerticalScrollBarVisibility="Auto"
Text="{Binding StartUpText}"
AcceptsReturn="True"
TextWrapping="Wrap" TextChanged="text_TextChanged" Loaded="text_Loaded" />
</DockPanel>
</StackPanel>
C#:
public MainWindow()
{
InitializeComponent();
this.DataContext=this;
StartUpText = " ";
}
private string startUpText;
public string StartUpText
{
get { return startUpText; }
set
{
if (value != startUpText)
{
startUpText = value;
}
}
}
这篇关于TextBox 上的 MinLines 和 MaxLines 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文