简体   繁体   中英

Xaml Binding Panorama Windows Phone 8

This is starting to annoy me, but I must be making some very simple mistake. I currently have the following XAML code:

 <Grid x:Name="LayoutRoot" 
       DataContext="{StaticResource JourneyViewModel}">
    <phone:Panorama Title="Journeys" 
                    ItemsSource="{Binding journeys}">
        <DataTemplate>
            <TextBlock Text="{Binding name}" />
        </DataTemplate>

    </phone:Panorama>
</Grid>

which works until I need to initialize the textblock with the name. I have items that are provided by the "journeys" parameters. However, I want to extract the name of the journey and put it into the textblock which simply is not working. My guess is that my XAML code is not correctly done. The following are the classes used:

    public ObservableCollection<JourneyModel> journeys
    {
        get
        {
            //I can verify with the debugger 
            //that this is not null and 
            //the variables inside the JourneyModels are set
            return _journeyModels;
        }
    }

And the JourneyModel:

 public string name
 {
      get { return _journey.name; }
      set
      {
          if (_journey.name != value)
                 _journey.name = value;
      }
 }

You can correct me if I am setting up the MVVM correctly, this is my first dash at it. Please let me know if you need more code bits. I hope I make the issue clear enough. Any help is greatly appreciated!

EDIT:

Loading ViewModel:

<UserControl.Resources>
    <my:JourneyViewModel  x:Key="JourneyViewModel"/>
</UserControl.Resources>

The code is fine but you're not able to see the TextBlock itself. You need to put the DataTemplate within an ItemTemplate or HeaderTemplate .

<phone:Panorama Title="Journeys" ItemsSource="{Binding journeys}">
   <phone:Panorama.HeaderTemplate>
      <DataTemplate>
         <TextBlock Text="{Binding name}" />
      </DataTemplate>
   </phone:Panorama.HeaderTemplate>
</phone:Panorama>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM