文本框不水平拉伸
TextBox not stretching horizontally
我无法水平拉伸文本框以适合其容器。
注意:
我确实设置了 HorizontalAlignment 属性。
我也试过将文本框的宽度绑定到它的容器宽度。
都不适合我。
<ListView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ConsoleLines}" Background="Black" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding ElementName=UserControl, Path=DataContext.Command, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextChanged="OnTextChanged" KeyDown="OnKeyDown"
HorizontalAlignment="Stretch" Padding="5" Background="Black" Foreground="LightGray" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
尝试将 ListView.HorizontalContentAlignment
Property 设置为 Stretch
。来自链接页面:
... you can set the HorizontalContentAlignment property to Stretch, which stretches the child element to fill the allocated space of the parent element
您一定误解了答案,因为它确实会在 GridView
的整个宽度上拉伸每个项目。试试这个:
<ListView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ConsoleLines}"
Background="Black" HorizontalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="Some simple text" Background="White"
Foreground="LightGray" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
您应该设置 ListView
的 HorizontalContentAlignment="Stretch"
<ListView ItemsSource="{Binding Collection, Source={StaticResource viewmodel}}" Background="Black" HorizontalContentAlignment="Stretch" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBox HorizontalAlignment="Stretch" Padding="0" Background="Green" Foreground="White" Text="" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
我无法水平拉伸文本框以适合其容器。
注意:
我确实设置了 HorizontalAlignment 属性。
我也试过将文本框的宽度绑定到它的容器宽度。
都不适合我。
<ListView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ConsoleLines}" Background="Black" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding ElementName=UserControl, Path=DataContext.Command, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextChanged="OnTextChanged" KeyDown="OnKeyDown"
HorizontalAlignment="Stretch" Padding="5" Background="Black" Foreground="LightGray" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
尝试将 ListView.HorizontalContentAlignment
Property 设置为 Stretch
。来自链接页面:
... you can set the HorizontalContentAlignment property to Stretch, which stretches the child element to fill the allocated space of the parent element
您一定误解了答案,因为它确实会在 GridView
的整个宽度上拉伸每个项目。试试这个:
<ListView Grid.Row="1" Grid.Column="0" ItemsSource="{Binding ConsoleLines}"
Background="Black" HorizontalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="Some simple text" Background="White"
Foreground="LightGray" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
您应该设置 ListView
的 HorizontalContentAlignment="Stretch"
<ListView ItemsSource="{Binding Collection, Source={StaticResource viewmodel}}" Background="Black" HorizontalContentAlignment="Stretch" >
<ListView.ItemTemplate>
<DataTemplate>
<TextBox HorizontalAlignment="Stretch" Padding="0" Background="Green" Foreground="White" Text="" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>