我有一個簡單的測試應用程序,用於找出我的ListView問題。除了我現在所擁有的東西,我還有兩件事需要完成。 1.使ListViewItems之間的間距小於默認值。我似乎無法弄清楚這是什麼樣的。 2.我有IsEnabled =「False」,這讓我有我想要的行爲,用戶無法與控件交互。但是,我不希望該項目褪色。想知道我需要調整哪些屬性才能做到這一點。UWP ListView如何控制項目高度 - ListViewItem周圍的區域
感謝您的幫助!
<Grid x:Name="GridBase" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" MinWidth="400">
<Grid Margin="30,20" Background="LightGray">
<ListView x:Name="MyList" ItemsSource="{Binding SourceData}" HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch" IsItemClickEnabled="False" Width="{Binding ElementName=GridBase,Path=Width}" MinWidth="400" MaxWidth="1200" IsEnabled="False">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="0,0"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.Header>
<Style TargetType="ListViewHeaderItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>
</ListView.Header>
<ListView.HeaderTemplate>
<DataTemplate>
<Grid Background="LightGreen" HorizontalAlignment="Stretch" Width="{Binding ElementName=MyList,Path=Width}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Col1" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" Text="Col2" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="2" Text="Col3" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="3" Text="Col4" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="4" Text="Col5" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="5" Text="Col6" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="6" Text="Col7" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="7" Text="Col8" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="8" Text="Col9" HorizontalAlignment="Left"/>
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Background="Aquamarine" Width="{Binding ElementName=MyList,Path=Width}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="6*"/>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Column1}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" Text="{Binding Column2}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="2" Text="{Binding Column3}" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="3" Text="{Binding Column4}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="4" Text="{Binding Column5}" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="5" Text="{Binding Column6}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="6" Text="{Binding Column7}" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="7" Text="{Binding Column8}" HorizontalAlignment="Center"/>
<TextBlock Grid.Column="8" Text="{Binding Column9}" HorizontalAlignment="Left"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
太棒了,非常感謝! –