3

I've just moved from Windows Phone 8.1 Silverlight to Windows Phone Store apps. I've the following XAML for an app page:

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

    <Grid x:Name="LayoutRoot">
        <Hub x:Name="Hub"
             Header="web clip"
             Background="{ThemeResource HubBackgroundImageBrush}">

            <HubSection x:Name="TileSelectorView"
                        Header="TILE SELECTOR">
                <DataTemplate>
                    <ListView x:Name="TileList"/>
                </DataTemplate>
            </HubSection>

            <HubSection x:Name="BrowserView"
                        Header="BROWSER">
                <DataTemplate>
                    <WebView x:Name="BrowserBox"/>
                </DataTemplate>
            </HubSection>

        </Hub>
    </Grid>
</Page>

Earlier, in Silverlight, I can access an element like TileList directly to do something like:

TileList.ItemsSource = <SomeItemSourceList>;

But now I'm unable to do that in the backend C# code. The TileList in itself is not accessible. However, TileSelectorView and BrowserView (ref: code above) are accessible.

I found these two questions where Jerry had answered to something similar:

  1. How to accessing Elements in XAML DataTemplate Listview without interacting with it
  2. How do I access a control inside a XAML DataTemplate?

However, I'm not able to replicate them. There is no Items property under my TileSelectorView to iterate through.

What am I doing wrong? How do I get about this?

Community
  • 1
  • 1
Rajshri Mohan K S
  • 1,557
  • 17
  • 30
  • Don't do `TileList.ItemsSource = ;`, do it properly by [binding to your data from XAML](https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758320.aspx). If you're not doing this yet: [implement the MVVM Pattern](https://msdn.microsoft.com/en-us/library/gg405484(v=pandp.40).aspx). – BCdotWEB Mar 16 '15 at 14:39
  • That's a lot of info! I'm going through it. Thanks a ton! – Rajshri Mohan K S Mar 17 '15 at 06:39

2 Answers2

1

you can databind them like this:

I've just moved from Windows Phone 8.1 Silverlight to Windows Phone Store apps. I've the following XAML for an app page:

<HubSection x:Name="TileSelectorView"
            Header="TILE SELECTOR" 
            ItemsSource="{Binding SomeItemSourceList}">
  <DataTemplate>
    <ListView x:Name="TileList"/>
  </DataTemplate>
</HubSection>

this assumes you are using the MVVM pattern which is a best practice when developing Windows Phone apps

https://msdn.microsoft.com/en-us/library/windows/apps/jj883732.aspx

personally i prefer MVVM Light as my MVVM framework: http://blog.galasoft.ch/posts/2014/04/building-a-universal-application-for-windows-phone-8-1-and-windows-8-1-with-mvvm-light/

GeertvdC
  • 2,758
  • 1
  • 22
  • 26
1

I ran into the same issue when moving from windows Phone Silverlight to Windows Phone RT. You can get around this issue by data binding as the others suggested but sometime you want to just get the control on the page. I found the following article quite helpful..

Get the controls inside DataTemplate control

Community
  • 1
  • 1
Stuart Smith
  • 1,931
  • 15
  • 26