简体   繁体   English

Xaml绑定Panorama Windows Phone 8

[英]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: 我目前有以下XAML代码:

 <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. 我的猜测是我的XAML代码未正确完成。 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. 如果我正确设置了MVVM,则可以纠正我,这是我的第一个破折号。 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: 加载ViewModel:

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

The code is fine but you're not able to see the TextBlock itself. 该代码很好,但是您看不到TextBlock本身。 You need to put the DataTemplate within an ItemTemplate or HeaderTemplate . 您需要将DataTemplate放在ItemTemplateHeaderTemplate

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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