2017-10-16 107 views
0
<GridView x:Name="MyGrid" SelectionMode="Multiple" IsItemClickEnabled="True" IsRightTapEnabled="False" RightTapped="MyGrid_RightTapped" BorderThickness="0" ItemClick="GridView_ItemClick"> 
    <GridView.ItemTemplate> 
     <DataTemplate> 
      <StackPanel Width="290" Height="80" HorizontalAlignment="Center" BorderThickness="0" Margin="5,5,5,5" Background="#596A82"> 
       <TextBlock FontSize="20" Margin="10,5,10,5" Text="{Binding Brand}" HorizontalAlignment="Left" Foreground="#FFFFFF"/> 
       <TextBlock FontSize="12" Margin="10,0,10,0" Text="{Binding Model}" HorizontalAlignment="Left" Foreground="#BDC3CD"></TextBlock> 
       <TextBlock FontSize="12" Margin="10,4,10,5" Text="{Binding Color}" HorizontalAlignment="Left" Foreground="#BDC3CD"></TextBlock> 
      </StackPanel> 
     </DataTemplate> 
    </GridView.ItemTemplate> 
</GridView> 

而且我有一個按鈕,當它點擊時,我需要在GridView中將SelectionMode屬性分配給多個。分配選擇模式到Gridview

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    MyGrid.SelectionMode = SelectionMode.Multiple; 
} 

但它不工作,並顯示這樣的錯誤。

無法隱式轉換類型 'Windows.UI.Xaml.Controls.SelectionMode' 到 'Windows.UI.Xaml.Controls.ListViewSelectionMode'。一個明確的 轉換不存在(是否缺少強制轉換?)

回答

1

使用ListViewSelectionMode而不是SelectionMode

MyGrid.SelectionMode = ListViewSelectionMode.Multiple;