PivotItem header style when Pivots ItemsSource is

2019-09-02 04:26发布

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>

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

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>

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..

1条回答
可以哭但决不认输i
2楼-- · 2019-09-02 05:05

V.G.,

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.

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.

查看更多
登录 后发表回答