2013-10-25 23 views
0

我正在创建一个wp8应用程序。我有两个视图和两个的ViewModels:WP8在第二个视图中绑定数据

VMMainPage vmMainPage - > MainPage.xaml中 VMresortInfo vmResortInfo - > resortInfo.xaml

第一个是工作的罚款。但是,当我尝试使用其视图模型绑定第二个视图时,我遇到了问题。

首先,在我的App.xaml.cs中,我已经初始化了vmResortInfo,就像我已经完成了vmMainPage一样。

private static VMresortInfo vmResortInfo = null; 
    public static VMresortInfo VmResortInfo 
    { 
     get 
     { 
      if (vmResortInfo == null) 
      { 
       vmResortInfo = new VMresortInfo(); 
      } 
      return vmResortInfo; 
     } 
    } 

然后,在resortInfo.xaml.cs我改变了观点的DataContext的:

public resortInfo() 
    { 
     InitializeComponent(); 
     DataContext = App.VmResortInfo; 

    } 

最后,我尝试将视图与视图模型绑定如下:

 <phone:PivotItem Header="info"> 
      <ItemsControl ItemsSource="{Binding resort}"> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 
         <Grid> 

         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="2*"/> 
          <ColumnDefinition Width="4*"/> 
         </Grid.ColumnDefinitions> 

          <StackPanel Margin="5,5,5,5" Grid.Column="0"> 
           <TextBlock Text="{Binding status}"/> 
           <TextBlock Text="{Binding name}"/> 
          </StackPanel>    
         </Grid> 
        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
      </ItemsControl> 
     </phone:PivotItem> 

的VMresortInfo是:

public class VMresortInfo 
{ 
    private Resort resort {get; set;} 

    public VMresortInfo() 
    { 
     this.resort = new Resort(); 
     this.resort.name = "NAME"; 
     this.resort.status = "abierta"; 
     this.resort.imageURL = new Uri("/Assets/fm.png", UriKind.RelativeOrAbsolute); 
    } 

    public void setName(string resortNameSelected) 
    { 
      this.resort.name = resortNameSelected; 
    } 
} 

但是,当我运行应用程序..没有信息显示。

Thx提前。

回答

0

OMG ......我自己复杂不必要...

 <phone:PivotItem Header="info">       
      <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="2*"/> 
         <ColumnDefinition Width="4*"/> 
        </Grid.ColumnDefinitions> 

        <StackPanel Margin="5,5,5,5" Grid.Column="0"> 
         <TextBlock Text="{Binding resort.name}"/> 
         <TextBlock Text="{Binding resort.status}"/> 
        </StackPanel>    
      </Grid>     
     </phone:PivotItem> 

问候

相关问题