【发布时间】:2014-10-22 13:26:27
【问题描述】:
我正在应用 MVVM 模式,当我为数据创建 ViewModel 时,我将我的数据透视的 ItemsSource 设置如下:
<Pivot ItemsSource="{Binding DataContext}" x:Name="TripsSegmentsPivot" Title=" " Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Margin="0" Grid.Row="1"/>
但我希望我的枢轴项目具有这样的标题
<PivotItem.Header>
<TextBlock Margin="0, 16, 0, 0" Text="settings" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
</PivotItem.Header>
在 xaml 或代码隐藏的什么位置设置它,如果是最后一个,究竟在 ViewModel 的哪个位置?
这就是我的 Pivot xaml 在 MainPage.xaml 中的样子:
<Pivot ItemsSource="{Binding DataContext}" x:Name="TripsSegmentsPivot" Title=" " Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Margin="0" Grid.Row="1">
<Pivot.ItemTemplate>
<DataTemplate>
<PivotItem Margin="8,8,8,0">
<PivotItem.Header>
<TextBlock Margin="0, 16, 0, 0" Text="{Binding S}" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
</PivotItem.Header>
</PivotItem>
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
在 MainPage.xaml.cs 我有
this.DataContext = new MyPageViewModel();
var viewModel = (MyPageViewModel)this.DataContext;
if (true == viewModel.LoadDataCommand.CanExecute(null))
{
viewModel.LoadDataCommand.Execute(null);
}
但是什么都没有发生..
【问题讨论】: