简体   繁体   中英

Binding Item Template dynamically in Pivot Windows phone 8.1

I am having multiple sections in pivot item with a same Item Template .

Below is my xaml part of the pivot

<Page
    x:Class="Namespace.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Namespace"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ViewModels="Namespace.ViewModels"
    xmlns:q42controls="using:Q42.WinRT.Controls"
    mc:Ignorable="d">

    <Page.Resources>
        <ViewModels:ViewModel x:Key="ViewModel" />
        <DataTemplate x:Key="headerTemplate">
            <TextBlock Text="{Binding Title}" FontSize="16"/>
        </DataTemplate>
        <DataTemplate x:Key="pivotTemplate">
            <ListView x:Name="listView" Background="White" ItemsSource="{Binding Articles}" 
                      HorizontalAlignment="Left" Margin="-25 0 -25 0" SelectionChanged="getIndex">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Tapped="StackPanel_Tapped">
                            <Grid>
                                <Grid.Background>
                                    <ImageBrush AlignmentX="Center" AlignmentY="Center" ImageSource="Assets/PlaceHolder.jpg"></ImageBrush>
                                </Grid.Background>
                                <Image x:Name="ArticleImage" q42controls:ImageExtensions.CacheUri="{Binding ImageURL}"></Image>                                
                            </Grid>
                            <StackPanel>
                                <TextBlock x:Name="HeadLine" Text="{Binding HeadLine}" 
                                               Margin="10 5 10 -5" TextWrapping="Wrap" 
                                               FontSize="20"
                                               FontFamily="{StaticResource HeadlineCommonFamiy}"
                                               Pivot.SlideInAnimationGroup="GroupTwo"
                                               FontWeight="Bold" TextTrimming="CharacterEllipsis" Height="63"/>

                                <TextBlock Text="{Binding Abstract}" TextWrapping="Wrap" FontSize="15"
                                   Pivot.SlideInAnimationGroup="GroupTwo" Margin="10 5 0 10"
                                           FontFamily="{StaticResource AbstractCommonFamily}"/>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </DataTemplate>
    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar Foreground="Black" ClosedDisplayMode="Minimal" Background="White">
            <CommandBar.PrimaryCommands>
                <AppBarButton x:Uid="Refresh" Icon="Refresh" Label="Refresh" Tapped="RefreshButton_Tapped"/>
            </CommandBar.PrimaryCommands>
            <CommandBar.SecondaryCommands>
                <AppBarButton x:Uid="Favourites" Icon="Favorite" Label="Favourites" Tapped="Favourites_Tapped"/>
                <AppBarButton x:Uid="Settings" Icon="Setting" Label="Settings" Tapped="Settings_Tapped"/>
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    <Grid Style="{StaticResource MyGridStyle}">
        <Grid x:Name="LoadingGrid" Visibility="Visible">
            <ProgressRing x:Name="progressRing" IsActive="True" Foreground="White" HorizontalAlignment="Center" Width="60"
                          Height="50" VerticalAlignment="Center" Margin="0 20 0 0"></ProgressRing>
        </Grid>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="60"></RowDefinition>
                <RowDefinition Height="45"></RowDefinition>
                <RowDefinition Height="*"></RowDefinition>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0">
                <Image Source="Assets/_logo.png" HorizontalAlignment="Center" Margin="1 5 0 0"></Image>
            </Grid>

            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid Grid.Column="0">
                    <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="&#xE700;"
                            Width="60" Height="60" Background="Transparent" Margin="-10 -20 0 0" 
                            Click="HamburgerButton_Click" Foreground="White"/>
                </Grid>
                <Grid Grid.Column="1">
                    <TextBlock Text="சினிமா" HorizontalAlignment="Center" FontSize="30" 
                           Margin="-50 0 0 0" Foreground="White"></TextBlock>
                </Grid>
            </Grid>

            <Grid Grid.Row="2" x:Name="galleryGrid" Visibility="Collapsed">
                <SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False" 
                           CompactPaneLength="0" OpenPaneLength="220">
                    <SplitView.Pane>
                        <ListView x:Name="menuBindList" Style="{StaticResource MyListViewStyle}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <StackPanel Orientation="Horizontal" Tag="{Binding SectionName}">
                                            <TextBlock Text="{Binding TitleofAccess}"
                                                   Tag="{Binding SectionName}" FontSize="18" 
                                                   VerticalAlignment="Center" Foreground="White" Tapped="MenuTextBlock_Tapped" />
                                        </StackPanel>
                                    </StackPanel>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </SplitView.Pane>
                    <SplitView.Content>
                        <ScrollViewer Name="cinemaScroll">
                            <Pivot DataContext="{StaticResource ViewModel}" x:Name="galleryPivot" 
                                    HeaderTemplate="{StaticResource headerTemplate}" 
                                    ItemTemplate="{StaticResource pivotTemplate}" ItemsSource="{Binding Feeds}" 
                                    Margin="0,-10,0,10" SelectionChanged="galleryPivot_SelectionChanged">

                                <Pivot.Resources>
                                    <Style TargetType="PivotHeaderItem">
                                        <Setter Property="CharacterSpacing" Value="{ThemeResource PivotHeaderItemCharacterSpacing}" />
                                        <Setter Property="Background" Value="Transparent" />
                                        <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
                                        <Setter Property="Padding" Value="{ThemeResource PivotHeaderItemMargin}" />

                                        <Setter Property="VerticalContentAlignment" Value="Center" />
                                        <Setter Property="IsTabStop" Value="False" />
                                        <Setter Property="RequestedTheme" Value="Dark" />
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="PivotHeaderItem">
                                                    <Grid 
                        x:Name="Grid"
                        Background="{TemplateBinding Background}">
                                                        <Grid.Resources>
                                                            <Style x:Key="BaseContentPresenterStyle" TargetType="ContentPresenter">
                                                                <Setter Property="FontFamily" Value="Segoe UI"/>
                                                                <Setter Property="FontWeight" Value="SemiBold"/>
                                                                <Setter Property="FontSize" Value="15"/>
                                                                <Setter Property="TextWrapping" Value="Wrap"/>
                                                                <Setter Property="LineStackingStrategy" Value="MaxHeight"/>
                                                                <Setter Property="TextLineBounds" Value="Full"/>
                                                                <Setter Property="OpticalMarginAlignment" Value="TrimSideBearings"/>
                                                            </Style>
                                                            <Style x:Key="BodyContentPresenterStyle" TargetType="ContentPresenter" BasedOn="{StaticResource BaseContentPresenterStyle}">
                                                                <Setter Property="FontFamily" Value="{ThemeResource PivotHeaderItemFontFamily}" />
                                                                <Setter Property="FontWeight" Value="{ThemeResource PivotHeaderItemThemeFontWeight}"/>
                                                                <Setter Property="FontSize" Value="{ThemeResource PivotHeaderItemFontSize}"/>
                                                            </Style>
                                                        </Grid.Resources>
                                                        <VisualStateManager.VisualStateGroups>
                                                            <VisualStateGroup x:Name="SelectionStates">
                                                                <VisualStateGroup.Transitions>
                                                                    <VisualTransition From="Unselected" To="UnselectedLocked" GeneratedDuration="0:0:0.33" />
                                                                    <VisualTransition From="UnselectedLocked" To="Unselected" GeneratedDuration="0:0:0.33" />
                                                                </VisualStateGroup.Transitions>
                                                                <VisualState x:Name="Disabled">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                       Storyboard.TargetProperty="Foreground" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseMediumLowBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="Unselected" />
                                                                <VisualState x:Name="UnselectedLocked">
                                                                    <Storyboard>
                                                                        <DoubleAnimation Storyboard.TargetName="ContentPresenterTranslateTransform"
                                                         Storyboard.TargetProperty="X"
                                                         Duration="0" To="{ThemeResource PivotHeaderItemLockedTranslation}" />
                                                                        <DoubleAnimation Storyboard.TargetName="ContentPresenter"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Duration="0" To="0" />
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="Selected">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                       Storyboard.TargetProperty="Foreground" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseHighBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"
                                                                       Storyboard.TargetProperty="Background" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#FF42424C" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="UnselectedPointerOver">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                       Storyboard.TargetProperty="Foreground" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"
                                                                       Storyboard.TargetProperty="Background" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="SelectedPointerOver">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                        Storyboard.TargetProperty="Foreground" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"
                                                                       Storyboard.TargetProperty="Background" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="UnselectedPressed">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                       Storyboard.TargetProperty="Foreground" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"
                                                                       Storyboard.TargetProperty="Background" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                                <VisualState x:Name="SelectedPressed">
                                                                    <Storyboard>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                                                       Storyboard.TargetProperty="Foreground" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightAltBaseMediumHighBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Grid"
                                                                       Storyboard.TargetProperty="Background" >
                                                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}" />
                                                                        </ObjectAnimationUsingKeyFrames>
                                                                    </Storyboard>
                                                                </VisualState>
                                                            </VisualStateGroup>
                                                        </VisualStateManager.VisualStateGroups>
                                                        <ContentPresenter
                            x:Name="ContentPresenter"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            Margin="{TemplateBinding Padding}"
                            FontSize="{TemplateBinding FontSize}"
                            FontFamily="{TemplateBinding FontFamily}"
                            FontWeight="{TemplateBinding FontWeight}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                                            <ContentPresenter.RenderTransform>
                                                                <TranslateTransform x:Name="ContentPresenterTranslateTransform" />
                                                            </ContentPresenter.RenderTransform>
                                                        </ContentPresenter>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </Pivot.Resources>
                            </Pivot>
                        </ScrollViewer>
                    </SplitView.Content>
                </SplitView>
            </Grid>
        </Grid>
    </Grid>
</Page>

I need to change the Item Template for a specific section dynamically. How can i achieve this. The section will contains image and we need to change the whole Item template and there we have redirection inside the pivot. How to obtain the scenario.

Below is the image design need to bind for the particular section

1st list of items like below 在此处输入图片说明

Likewise it contains list of items. In tapping of each section redirect to the below 在此处输入图片说明

In tapping of single image take us to

在此处输入图片说明

Tapping will redirect to the below part 在此处输入图片说明

The above process will be carried out in a single pivot item. Will it be possible. If it's possible how to attain this. Please someone guide me to solve this

As per my understanding would suggest some of the methods in which you can achieve this

<Pivot >...
      <PivotItem x:Uid="OVERVIEW" Header="" Margin="0">
                        <Grid>...
                        </Grid>
      </PivotItem>.......
    </Pivot>
  • Would be specifying ItemTemplate for the specific pivot inside that pivot Item. If the changes are specific for each pivot

  • Another way would be using this Link You can instead even use Converters and based on your data can make grids visible invisible etc. But you will need to identify what your triggers for ItemTemplate changed are based on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM