0
votes

Created a Hub App in WP8.1, I have a ListView that i need to modify the selection mode when the appbar button is pressed. I cannot access the x:Name given to the listview in the .cs code behind. I have had this working on a normal page, just not working in the Hub App.

I cant access the x:Name="WeatherListView" in the c# to change the selectionmode

<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(object sender, RoutedEventArgs e) {

        SetDefaultWeatherButton(false);
        SetWeatherDeleteButton(true);
    }
1

1 Answers

0
votes

Can't access <Controls> like that if it is part of a <DataTemplate>, you need to browse the VisualTree and extract it out or Databind the SelectionMode to a property in your ViewModel. And changing this Property should change the SelectionMode if done correctly.


VisualTree Exaction Example, I recommend using the Databinding Method however.