使用Hub应用程序在c#中加速ListView.selctionMode

本文关键字:加速 ListView selctionMode Hub 应用程序 使用 | 更新日期: 2023-09-27 18:27:23

在WP8.1中创建了一个Hub应用程序,我有一个ListView,当按下appbar按钮时,我需要修改选择模式。我无法访问在后面的.cs代码中为列表视图指定的x:Name。我在一个正常的页面上工作过,只是没有在Hub应用程序中工作。

我无法访问c#中的x:Name="WeatherListView"来更改选择模式

<Grid x:Name="LayoutRoot">
    <!--TODO: Content should be placed within the following grid-->
    <Grid Grid.Row="0" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <Hub x:Name="AHubView" x:Uid="Hub" Header="A View" SectionsInViewChanged="AHubVieww_SectionsInViewChanged" >
            <!--Background="{ThemeResource HubBackgroundImageBrush}"-->
            <HubSection Name="WeatherHub" x:Uid="WeatherHub" Header="Weather Hub" DataContext="{Binding HubData}"  
                        d:DataContext="{Binding}"
                        >
                <DataTemplate  >
                    <ListView
                        x:Name="WeatherListView"
                        SelectionMode="Multiple"
                        ItemClick="WeatherListView_OnItemClick"
                         ItemsSource="{Binding DataVal}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <StackPanel>

private void WeatherRemoveAppBarButton_OnClick(对象发送方,RoutedEventArgs e){

        SetDefaultWeatherButton(false);
        SetWeatherDeleteButton(true);
    }

使用Hub应用程序在c#中加速ListView.selctionMode

无法访问<Controls>,如果它是<DataTemplate>的一部分,则需要浏览VisualTree并将其提取出来,或者将SelectionMode数据绑定到ViewModel中的属性。如果操作正确,更改此属性应该会更改SelectionMode。


VisualTree示例,我建议使用Databinding方法。