有什麼辦法如何告訴組件在WPF採取可用空間的100%?如何設置寬度爲100%,在WPF
像
width: 100%;
在CSS
我有了這個XAML,我不知道如何強制電網採取100%的寬度。
<ListBox Name="lstConnections">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="LightPink">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=User}" Margin="4"></TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Password}" Margin="4"></TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Path=Host}" Margin="4"></TextBlock>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
結果看起來像
alt text http://foto.darth.cz/pictures/wpf_width.jpg
我做到了粉紅色所以很明顯有多少空間沒有考慮。我需要使粉紅色的網格100%的寬度。
Link是死了... – 2017-03-10 14:02:18
@MartiniBianco我很抱歉,但這個問題是8歲。我甚至不記得照片中的內容,從那時起我也沒有使用過WPF。 – 2017-03-11 13:01:50