2016-04-16 76 views
0

我有一個簡單的測試應用程序,用於找出我的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> 

回答

0

如果你想獲得ListViewItems之間的間距小於默認的,你應該做的ListViewItem的保證金,使頂部或BUTTOM少。

0

爲了解決1.您可以通過添加

<Setter Property="Margin" Value="-10,-10,-10,-10"/> 

<Style TargetType="ListViewItem">

只是調整的ListViewItem的保證金爲解決2.設置IsHitTestVisible="False"在你的ListView。

+0

太棒了,非常感謝! –

相關問題