请帮我理解。我有PanoramaPage.xaml
两个视图PanoramaItem
。第一项是来自某个 Web 服务的新闻列表,第二项是该服务的用户列表。新闻和用户不同Models
。
看法:
<controls:PanoramaItem Header="users">
<ListBox Margin="0,0,-12,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="0,0,0,17">
<StackPanel Width="311">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Aboutself}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
</controls:Panorama>
<controls:PanoramaItem Header="news">
<ListBox Margin="0,0,-12,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432" Height="78">
<TextBlock Text="{Binding Title}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
<TextBlock Text="{Binding Content}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
在MVVM
我应该有两个 ViewModel
用于两个控件NewsListBox
和 UsersListBox
或一个 ViewModel
用于一个 xaml PanoramaPage.xaml
。
全景页面视图模型
public class PanoramaPageViewModel : INotifyPropertyChanged
{
private ObservableCollection<User> userDataSource;
private ObservableCollection<News> newsDataSource;
public ObservableCollection<User> UserDataSource
{
get
{
if (this.userDataSource == null)
{
this.userDataSource = new ObservableCollection<User>();
}
return this.userDataSource;
}
}
public ObservableCollection<News> NewsDataSource
{
get
{
if (this.newsDataSource == null)
{
this.newsDataSource = new ObservableCollection<News>();
}
return this.newsDataSource;
}
}
// LoadUsers(), LoadNews(), etc
}
或者
用户视图模型
public class UsersViewModel : INotifyPropertyChanged
{
private ObservableCollection<User> userDataSource;
public ObservableCollection<User> UserDataSource
{
get
{
if (this.userDataSource == null)
{
this.userDataSource = new ObservableCollection<User>();
}
return this.userDataSource;
}
}
//LoadUsers() etc
}
新闻视图模型
public class NewsViewModel : INotifyPropertyChanged
{
private ObservableCollection<News> newsDataSource;
public ObservableCollection<News> NewsDataSource
{
get
{
if (this.newsDataSource == null)
{
this.newsDataSource = new ObservableCollection<News>();
}
return this.newsDataSource;
}
}
//LoadNews() etc
}
你怎么看?