TextBox当文本不再适合一行时,如何配置控件以自动垂直调整自身大小?
例如,在以下XAML中:
<DockPanel LastChildFill="True" Margin="0,0,0,0">
<Border Name="dataGridHeader"
DataContext="{Binding Descriptor.Filter}"
DockPanel.Dock="Top"
BorderThickness="1"
Style="{StaticResource ChamelionBorder}">
<Border
Padding="5"
BorderThickness="1,1,0,0"
BorderBrush="{DynamicResource {ComponentResourceKey TypeInTargetAssembly=dc:NavigationPane,
ResourceId={x:Static dc:NavigationPaneColors.NavPaneTitleBorder}}}">
<StackPanel Orientation="Horizontal">
<TextBlock
Name="DataGridTitle"
FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource {ComponentResourceKey
TypeInTargetAssembly=dc:NavigationPane,
ResourceId={x:Static dc:NavigationPaneColors.NavPaneTitleForeground}}}"/>
<StackPanel Margin="5,0" Orientation="Horizontal"
Visibility="{Binding IsFilterEnabled, FallbackValue=Collapsed, Mode=OneWay, Converter={StaticResource BooleanToVisibility}}"
IsEnabled="{Binding IsFilterEnabled, FallbackValue=false}" >
<TextBlock />
<TextBox
Name="VerticallyExpandMe"
Padding="0, 0, 0, 0"
Margin="10,2,10,-1"
AcceptsReturn="True"
VerticalAlignment="Center"
Text="{Binding QueryString}"
Foreground="{DynamicResource {ComponentResourceKey
TypeInTargetAssembly=dc:NavigationPane,
ResourceId={x:Static dc:NavigationPaneColors.NavPaneTitleForeground}}}">
</TextBox>
</StackPanel>
</StackPanel>
</Border>
</Border>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
TextBox名为"VerticallyExpandMe" 的控件需要在绑定到它的文本不适合一行时自动垂直展开.随着AcceptsReturn设置为true,TextBox垂直展开,如果我按在它进入,但我想它不自动执行此操作.
我有以下的JS Fiddle来展示我想要实现的目标:http: //jsfiddle.net/sVKU8/2/
1)我假设第一部分很容易 - 有没有办法更新父label类,width根据两个孩子<div>的总宽度自动设置它,所以边框只包围绿色和红色<div>s?我认为设置width: auto应该这样做,但我的CSS技能显然缺乏.
2)接下来我想要完成的是width从我的label-text类中删除属性并设置宽度(或者如果可能的话自动增长)每当我<div>通过JavaScript 将文本应用到文本时(即保持原始高度)该label班).
我不确定是否需要尝试根据实际文本计算宽度,或者是否有办法仅使用宽度设置应用文本以允许其增长.
任何意见或建议将不胜感激!
有谁知道如何动态地将RichTextBox控件调整为其内容?
我在应用程序中遇到TextBox问题...
窗口有一个带两列的网格.左列包含一个具有恒定宽度但具有适应高度的控件.右列包含一个TextBox,它占用Grid中的所有剩余空间(从而占用Window).
Grid具有最小的宽度和高度,并包含在ScrollViewer中.如果用户将窗口的大小调整为小于Grid的最小widht/height,则会显示滚动条.
这正是我想要的.但是,当用户开始键入文本时会出现问题.如果文本要长到适合TextBox中的一行,我希望文本换行.因此我在TextBox上设置了TextWrapping ="Wrap".但由于TextBox具有自动宽度并且包含在ScrollViewer中(实际上是包裹的整个Grid),因此TextBox只是向右扩展.
如果窗口展开,我确实希望TextBox扩展,但我不希望TextBox按文本扩展.而是文本应该包装在可用的TextBox中.如果文本不适合TextBox高度,则应在TextBox中显示滚动条.
有没有办法实现这个目标?
下面是一些显示我的问题的代码.
<Window x:Class="AdaptingTextBoxes.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="400" Background="DarkCyan">
<Grid Margin="10" Name="LayoutRoot">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Grid MinWidth="300" MinHeight="200">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Margin="0,0,10,0" Content="Button" Width="100" />
<TextBox Grid.Column="1" AcceptsReturn="True" TextWrapping="Wrap" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</Grid>
</ScrollViewer>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud) 我有一个包含flowlayout面板的groupbox,flowlayout面板包含一堆控件.我将flowlayout面板设置为与父级对接.由于我不知道面板中有多少控件,我将组框autosize设置为true,autosizemode设置为增长和缩小.当我这样做时,groupbox会缩小,就像它是空的一样.我需要标题,所以我无法删除组框.任何人都知道为什么会这样吗?
我有很多情况下我有自动调整大小的面板或网格,但是如果它们包含一个TextBoxwith TextWrapping="Wrap",TextBox则会在它真正需要之前将面板/网格继续向右扩展,例如下面的图像:

我想要做的是TextBox通过在尝试向右扩展之前包装文本来填充其区域.该问题的简化示例是:
<Grid>
<Grid Background="Black" />
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox TextWrapping="Wrap" Height="120" MinWidth="200" />
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
我在这里找到了类似的问题,但是发布的最佳解决方案不允许TextBox扩展.该解决方案类似于:
<Grid>
<Grid Background="Black">
</Grid>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border BorderThickness="0" x:Name="border" Margin="0.5" />
<TextBox TextWrapping="Wrap" Height="120" MinWidth="200" Width="{Binding ActualWidth, ElementName=border}" />
</Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)
除了TextBox使用修改过的行为进行扩展之外 谢谢!
我正在寻找一种方法让CSS(3)能够自动调整float:leftdiv和float:rightdiv 之间的中心容器div的宽度.
中心div还需要具有一min-width组的功能,类似于谷歌+ - >主页,其中中心内容自动安装在左侧导航按钮和右侧聊天窗格之间.然后,当屏幕宽度缩小超过某一点(使用javascript检测)时,聊天窗格最小化以节省空间.
这是一个活跃的模拟工作:http://jsfiddle.net/9vrby/
另外,这是我现在使用的css代码:
#left{ float:left; width:200px; height:400px; border:1px solid #000; }
#center{ float:left; width:auto; height:400px; border:1px solid red; }
#right{ float:right; width:100px; height:400px; border:1px solid blue; }
Run Code Online (Sandbox Code Playgroud)
如果您需要更多信息,请告诉我,并提前感谢您的帮助.
我有一个TextBlock我需要自动调整到宽度的一个TreeView.这些TreeView和TextBlock都包含在一个StackPanel.在StackPanel里面Expander.宽度TreeView应该驱动其他对象的宽度,我需要TextBlock更改的高度来显示全文.我所有的努力都导致了TextBlock驱动宽度.谢谢!
<Expander IsEnabled="True" HorizontalAlignment="Right" Margin="0,8,8,53" x:Name="ExpanderBookMarks" Width="Auto" Foreground="#FF625B5B" ExpandDirection="Down" IsExpanded="True" Header="Bookmarks" Visibility="Hidden">
<StackPanel Name ="StackPanelBookmark" Orientation="Vertical" Width="{wpf:Binding Path=Width, ElementName=trvBookmarks, Mode=Default}">
<TreeView x:Name="trvBookmarks" ItemsSource="{Binding}"
ItemTemplateSelector="{StaticResource BookmarkTemplateSelector}"
Margin="0,0,0,0"
TreeViewItem.Selected="HandleTreeViewItemClick" AllowDrop="True"/>
<TextBlock x:Name="TextBlockBookmarkDiscription" TextWrapping="Wrap" Foreground="AntiqueWhite" Background="Transparent" Width="150">
This is the discription area and needs to be very long because the end user can put 400 charectors in.
</TextBlock>
</StackPanel>
<!--End of Dougs Treeview--> …Run Code Online (Sandbox Code Playgroud) 我正在开发angular2 applciation.我需要自动调整textarea.我试图从https://github.com/stevepapa/angular2-autosize重用angular2-autosize
跟着自述文件,但我得到以下错误
未捕获错误:模块构建失败:错误:ENOENT:没有此类文件或目录,打开'C:\ Users\Vipin\SampleApp \node_modules\angular2-autosize\angular2-autosize.js'.
请建议如何克服这个问题.
autosize ×10
wpf ×4
textbox ×3
c# ×2
css ×2
angular ×1
autolayout ×1
containers ×1
groupbox ×1
html ×1
ios ×1
objective-c ×1
richtextbox ×1
textarea ×1
textblock ×1
width ×1
winforms ×1
xaml ×1
xcode8 ×1