让一个WPF文本框只和它拥有的房间一样宽,但随着空间的扩大而扩展?
注意文本框如何向右扩展,直到有足够的水平空间来容纳内容?嗯,我希望它不要扩展,并适合它在窗口中的空间文本 如果窗口展开,则其所在的Grid.Column将展开,但文本框本身应展开以适应。够简单吗 有什么建议吗?这是我第一次进入WPF,到目前为止,它是相当圆滑的 编辑:以下是我的XAML标记:让一个WPF文本框只和它拥有的房间一样宽,但随着空间的扩大而扩展?,wpf,xaml,textbox,width,Wpf,Xaml,Textbox,Width,注意文本框如何向右扩展,直到有足够的水平空间来容纳内容?嗯,我希望它不要扩展,并适合它在窗口中的空间文本 如果窗口展开,则其所在的Grid.Column将展开,但文本框本身应展开以适应。够简单吗 有什么建议吗?这是我第一次进入WPF,到目前为止,它是相当圆滑的 编辑:以下是我的XAML标记: <Window x:Class="GameLenseWpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xa
<Window x:Class="GameLenseWpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="450" Width="350" MinHeight="450" MinWidth="350">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0.15*" />
<RowDefinition />
</Grid.RowDefinitions>
<Image Grid.Row="0" Stretch="Fill" Source="Image/topBarBg.png" />
<StackPanel Orientation="Horizontal" Grid.Row="0">
<TextBlock Text="Platform"
Foreground="White"
FontFamily="Georgia"
FontSize="15"
Margin="10"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<ComboBox x:Name="cmbPlatform"
Margin="10"
FontFamily="Georgia"
FontSize="15"
MinHeight="30"
MinWidth="140"
VerticalAlignment="Center"
VerticalContentAlignment="Center" SelectionChanged="cmbPlatform_SelectionChanged">
<ComboBoxItem>All Platforms</ComboBoxItem>
<ComboBoxItem>Playstation 3</ComboBoxItem>
<ComboBoxItem>XBox 360</ComboBoxItem>
<ComboBoxItem>Wii</ComboBoxItem>
<ComboBoxItem>PSP</ComboBoxItem>
<ComboBoxItem>DS</ComboBoxItem>
</ComboBox>
</StackPanel>
<Image x:Name="imgAbout" Grid.Row="0" Source="Image/about.png"
Height="16" HorizontalAlignment="Right"
VerticalAlignment="Center"
Margin="0 0 10 0" />
<ListBox Grid.Row="1" x:Name="lstGames" Background="#343434" Padding="5">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="120" Margin="0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Border BorderBrush="#202020" BorderThickness="5" CornerRadius="4" Panel.ZIndex="0">
<Image Grid.Row="0" Grid.Column="0" Source="{Binding ImageUrl}" Stretch="Fill"/>
</Border>
<StackPanel Grid.Row="0" Grid.Column="1" Margin="12 0 0 0">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Title:" FontFamily="Arial" Foreground="White"/>
<TextBlock Text="{Binding Title}" FontFamily="Arial" Foreground="White" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Release Date:" FontFamily="Arial" Foreground="White" />
<TextBlock Text="{Binding ReleaseDate}" FontFamily="Arial" Foreground="White" />
</StackPanel>
<TextBlock Text="Synopsis" FontFamily="Arial" Foreground="White" />
<TextBox Background="#454545" Text="{Binding Synopsis}" MinHeight="76" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Window>
所有平台
游戏机3
XBox 360
Wii
PSP
DS
我认为您需要设置textbox控件的边距属性。在设计器中,您可以看到每个文本框周围都有小圆圈(因此,当您聚焦它们时,每个控件都有)。单击文本框右侧的小圆,使该控件随当前布局控件中的可用空间略微增大(通过单击该圆,边距将添加到XAML中)
我不知道你的图像中是否已经调整了窗口大小,但在该图像中,你似乎还需要设置文本框的宽度
这有帮助吗?要将文本框包装到列表框中,可以进行以下更改:
<ListBox Grid.Row="1" x:Name="lstGames" Background="#343434" Padding="5"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
HorizontalContentAlignment="Stretch" >
</ListBox>
<TextBox Text="{Binding Synopsis}" MinHeight="76" TextWrapping="Wrap" />
在没有看到您的XAML的情况下回答是不可能的。。。默认情况下,文本框会占用所有可用空间,但不会占用更多空间(HorizontalAlignment=Stretch)。您是如何在ListBox中定义ItemTemplate和ItemContainerStyle的?不,将margin(right)属性设置为其他属性没有帮助。它仍然扩展到右边。好的,很抱歉我误读了你最初的帖子。您需要为textbox设置TextWrapping属性。Sergio,这解决了您的问题吗?我用边距集(在我的原始答案中)和TextWrapping属性设置为Wrap来测试它。结果就是您描述的功能,文本将根据父布局控件的大小换行。不幸的是,这并没有解决我的问题:(你介意发布你的xaml吗?这样我就可以把它和我的区别开来,看看我的做法有什么不同。我也不明白设置边距和文本换行不能解决这个问题,但在我的机器上解决不了。在其他情况下,Fishz所描述的对我有用(特别是TextWrapping=“wrap”
-但我用您的精确代码尝试了它,但它没有像我预期的那样工作。我正在尝试查看我现在可以看到的内容。谢谢!设置列表框的内容对齐方式成功了。