将SelectionMode分配给Gridview

时间:2017-10-16 10:35:57

标签: c# gridview uwp uwp-xaml

<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属性分配给多个。

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

但是它没有工作并且显示出这样的错误。

  

无法隐式转换类型   &#39; Windows.UI.Xaml.Controls.SelectionMode&#39;至   &#39; Windows.UI.Xaml.Controls.ListViewSelectionMode&#39 ;.一个明确的   存在转换(你错过了演员吗?)

1 个答案:

答案 0 :(得分:1)

使用ListViewSelectionMode代替SelectionMode

MyGrid.SelectionMode = ListViewSelectionMode.Multiple;