2014-04-27 54 views
0

如何在Windows應用商店應用程序中更改ListView中的ListView項目選擇樣式?我想更改顏色,邊距並刪除複選框。我曾試圖改變各種Blend中的模板,但我想不出這一個:-(更改列表查看項目選擇樣式

enter image description here

XAML代碼:

<Page 
x:Class="WindowsStoreListViewSelectionTest.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:WindowsStoreListViewSelectionTest" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 
<Page.DataContext> 
    <local:BasicData/> 
</Page.DataContext> 

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <ListView ItemsSource="{Binding ListData}" SelectedIndex="1"> 
    </ListView> 
</Grid> 

C# - 代碼:

public class BasicData 
{ 
    public BasicData() 
    { 
     _ListData = new ObservableCollection<object>(); 
     ListData.Add("Alfa"); 
     ListData.Add("Beta"); 
     ListData.Add("Gamma"); 
    } 

    private ObservableCollection<object> _ListData; 

    public ObservableCollection<object> ListData 
    { 
     get 
     { 
      return _ListData; 
     } 
    } 
} 

回答

10

所以問題終於解決了:-)。以下是Windows 8.1項目的其他初學者的分步指南。這是Blend(一個偉大的工具 - 花一些時間來學習如何使用它),但我很確定它對Visual Studio來說或多或少是一樣的。

右鍵單擊列表視圖,然後選擇:

  • 編輯其他模板
  • 編輯生成的項容器(ItemContainerStyle)
  • 編輯副本
  • 輸入一個名稱

然後生成如下樣式:

<Style x:Key="ListViewItemStyle1" TargetType="ListViewItem"> 
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/> 
    <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/> 
    <Setter Property="Background" Value="Transparent"/> 
    <Setter Property="TabNavigation" Value="Local"/> 
    <Setter Property="IsHoldingEnabled" Value="True"/> 
    <Setter Property="Margin" Value="0,0,18,2"/> 
    <Setter Property="HorizontalContentAlignment" Value="Left"/> 
    <Setter Property="VerticalContentAlignment" Value="Top"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListViewItem"> 
       <ListViewItemPresenter 
        CheckHintBrush="{ThemeResource ListViewItemCheckHintThemeBrush}" 
        CheckBrush="{ThemeResource ListViewItemCheckThemeBrush}" 
        ContentMargin="4" 
        ContentTransitions="{TemplateBinding ContentTransitions}" 
        CheckSelectingBrush="{ThemeResource ListViewItemCheckSelectingThemeBrush}" 
        DragForeground="{ThemeResource ListViewItemDragForegroundThemeBrush}" 
        DragOpacity="{ThemeResource ListViewItemDragThemeOpacity}" 
        DragBackground="{ThemeResource ListViewItemDragBackgroundThemeBrush}" 
        DisabledOpacity="{ThemeResource ListViewItemDisabledThemeOpacity}" 
        FocusBorderBrush="{ThemeResource ListViewItemFocusBorderThemeBrush}" 
        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
        Padding="{TemplateBinding Padding}" 
        PointerOverBackgroundMargin="1" 
        PlaceholderBackground="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" 
        PointerOverBackground="{ThemeResource ListViewItemPointerOverBackgroundThemeBrush}" 
        ReorderHintOffset="{ThemeResource ListViewItemReorderHintThemeOffset}" 
        SelectedPointerOverBorderBrush="{ThemeResource ListViewItemSelectedPointerOverBorderThemeBrush}" 
        SelectionCheckMarkVisualEnabled="True" 
        SelectedForeground="{ThemeResource ListViewItemSelectedForegroundThemeBrush}" 
        SelectedPointerOverBackground="{ThemeResource ListViewItemSelectedPointerOverBackgroundThemeBrush}" 
        SelectedBorderThickness="{ThemeResource ListViewItemCompactSelectedBorderThemeThickness}" 
        SelectedBackground="{ThemeResource ListViewItemSelectedBackgroundThemeBrush}" 
        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

通過更改SelectionCheckMarkVisualEnabled值可輕鬆刪除複選標記。

0

你在找什麼是ListViewItem Style。這有邊界的定義,選擇標誌符號以及其他你想改變的東西。它通常通過ItemContainerStyle屬性在ListView中設置。

相關問題