我對WPF很新。我只是嘗試一些使用Grid和Listbox的佈局, ,但我有一些填充/間距/邊距/邊框(簡稱爲邊框 ),我無法脫身。網格和列表框有一些邊框我無法擺脫
邊框圍繞四個元素,元素本身沒有問題 並且它們之間沒有空間。
也嘗試過WPF Inspector,但是我找不到它來自哪裏。 沒有看到它。
這是我的XAML:
<Window x:Class="WpfElements.FourElements"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="FourElements" Height="701" Width="351">
<Grid Background="Red" Margin="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ListBox Margin="0" BorderThickness="0" Padding="0" Grid.Row="0" Grid.Column="0" Background="Lime" SelectionMode="Single" ItemsSource="{Binding Path=Texts}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding ItemText}" Grid.Row="{Binding Path=Row}" Grid.Column="{Binding Path=Col}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"></TextBox>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="Grid.Column" Value="{Binding Path=Col}"/>
<Setter Property="Grid.Row" Value="{Binding Path=Row}"/>
<Setter Property="ContentControl.HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="ContentControl.VerticalContentAlignment" Value="Stretch"/>
<Setter Property="ContentControl.Margin" Value="0"/>
<Setter Property="ContentControl.Padding" Value="0"/>
<Setter Property="Control.BorderThickness" Value="0"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Grid>
希望有人能幫助我擺脫這個邊界。非常感謝!
你能後的截圖外觀?您將在代表TextBox邊框的每個項目之間看到一條細線。 –