当支点的ItemsSource设置为DataContext的MVVM PivotItem标题样式 [英] PivotItem header style when Pivots ItemsSource is set to datacontext MVVM

查看:87
本文介绍了当支点的ItemsSource设置为DataContext的MVVM PivotItem标题样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯应用MVVM模式,当我创造了我的ViewModel为数据设置我枢轴的ItemsSource如下:

Im applying MVVM pattern and when I created my ViewModel for the Data I set the ItemsSource of my pivot as follows:

<Pivot ItemsSource="{Binding DataContext}" x:Name="TripsSegmentsPivot" Title=" " Foreground="#FF888888" Style="{StaticResource PivotStyle1}" SelectionChanged="Pivot_SelectionChanged" Margin="0" Grid.Row="1"/>

但我想我的支点项目已经称呼这样的标题

But I want my pivot items to have styled header like this

<PivotItem.Header>
    <TextBlock Margin="0, 16, 0, 0" Text="settings" Foreground="#FF888888" FontSize="32" FontFamily="Segoe WP" FontWeight="Light"/>
</PivotItem.Header>

在哪里设置这个在XAML,或code-后面,如果最后,在这里正好在视图模型以某种方式?

Where to set this in the xaml, or in the code-behind and if the last, where exactly in the ViewModel somehow?

这是我的支点XAML如何看起来像在MainPage.xaml中:

This is how my Pivot xaml looks like in 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中我有

In MainPage.xaml.cs I have

this.DataContext = new MyPageViewModel();

var viewModel = (MyPageViewModel)this.DataContext;

if (true == viewModel.LoadDataCommand.CanExecute(null))
{
   viewModel.LoadDataCommand.Execute(null);
}

但没有任何反应。

but nothing happens..

推荐答案

V.G。

我回答了你的问题,其中问题的根本原因是你的XAML包含的方式另一个在 PivotItem 里面的的DataTemplate 。简单地说,不这样做。 :)
这是您正在构建因此它可能会解决您的问题相同的应用程序。

I answered another one of your questions where the root cause of the issue was the way your XAML includes the PivotItem inside of the DataTemplate. Simply put, don't do that. :) This is from the same app you are building so it may fix your issue.

看看我的回答对 PivotItems结合后不调整和重构XAML什么,我形容。如果您仍然有与头绑定问题,请给我一个信息,我会回到这里,并帮助您解决问题。

Take a look at my answer for PivotItems do not resize after binding and refactor your XAML to what I describe. If you still have the issue with the header binding, please send me a message and I will come back here and help you fix it.

这篇关于当支点的ItemsSource设置为DataContext的MVVM PivotItem标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆