c# - Xaml 绑定(bind)全景 Windows Phone 8

标签 c# wpf windows-phone-7 xaml windows-phone-8

这开始让我烦恼,但我一定是犯了一些非常简单的错误。我目前有以下 XAML 代码:

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

    </phone:Panorama>
</Grid>

在我需要用名称初始化文本 block 之前一直有效。我有“旅程”参数提供的项目。但是,我想提取旅程的名称并将其放入根本不起作用的文本 block 中。我的猜测是我的 XAML 代码没有正确完成。以下是使用的类:

    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;
        }
    }

和 JourneyModel:

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

如果我正确设置了 MVVM,您可以纠正我,这是我的第一次尝试。如果您需要更多代码位,请告诉我。我希望我把问题说清楚了。非常感谢任何帮助!

编辑:

加载 View 模型:

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

最佳答案

代码没问题,但您看不到 TextBlock 本身。您需要将 DataTemplate 放在 ItemTemplateHeaderTemplate 中。

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

关于c# - Xaml 绑定(bind)全景 Windows Phone 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15683563/

相关文章:

c# - 带有填充的菜单项的悬停问题

c# - Entity Framework 6 单元测试 (NSubstitute) - 如何测试带有子对象的对象在未请求子对象时不返回子对象

wpf - 调整 WPF 列表或网格中的字体大小以正确使用空间

wpf - 使用 IsFocusScope 选项时如何阻止 FocusManager 将焦点移到打开的弹出窗口之外

c# - 文字 Uri 请求

c# - Windows.Navigation.NavigationMode Windows Phone 7

c# - 将 C# 对象列表转换为 JavaScript 对象数组

c# - WPF MVVM : How to disable clicked button and enable all other buttons?

api - Windows Phone 7 - 接听电话

c# - 具有不同线程安全模式的 System.Lazy<T>