Question

create Pivot control with dynamic pivot items, within the pivot datatemplate have to show Items control that too will have data template..like below

    <phone:Pivot x:Name="chatPivot" Margin="0 2 0 76" ItemsSource="{Binding Contacts}" SelectionChanged="chatPivot_SelectionChanged">                       <phone:Pivot.ItemTemplate>                      
                    <DataTemplate>

                        <ScrollViewer x:Name="chatScroll" Margin="0,0,0,72"  VerticalScrollBarVisibility="Auto">
                            <ItemsControl  Margin="0" x:Name="chats" Tap="chats_Tap_1" ItemsSource="{Binding Messages}"
                ItemTemplate="{StaticResource imgItemTemplate}"  ItemsPanel="{StaticResource imgItemPanel}">
                            </ItemsControl>
                        </ScrollViewer>

                    </DataTemplate>
                </phone:Pivot.ItemTemplate>
            </phone:Pivot>  

Here is my dataTemplate.

<phone:PhoneApplicationPage.Resources>

    <ItemsPanelTemplate x:Key="imgItemPanel">
        <StackPanel Orientation="Vertical" />
    </ItemsPanelTemplate>
    <DataTemplate x:Key="imgItemTemplate" >

        <chatbubble:ChatBubbleControl x:Name="ChatBubble" Hold="ChatBubbleControl_Hold_1"  />

    </DataTemplate>

    </phone:PhoneApplicationPage.Resources>
Was it helpful?

Solution

I actually do not know the design of your "ChatbubbleControl" usercontrol but I found one issue why values are not getting bound.

<phone:PhoneApplicationPage.Resources>

<ItemsPanelTemplate x:Key="imgItemPanel">
    <StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
<DataTemplate x:Key="imgItemTemplate" >

    <chatbubble:ChatBubbleControl x:Name="ChatBubble" xyz="{Binding}" Hold="ChatBubbleControl_Hold_1"  />

</DataTemplate>

</phone:PhoneApplicationPage.Resources>

You are binding value to ItemsControl but you are not binding any value to actual control (here, chatbubblecontrol) that is displaying the value on screen. The solution is the you need to create a property to your usercontrol e.g.: Here, I made a test property named "xyz". and then try to bind the values to it.

Hope this will help you conceptually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top