0

Im using Visual Studio 2013 with the Silverlight 5 Pivotviewer. Some years ago I already did some Pivotviewer stuff with the predecessor and it worked fine that way (Excel plugin tool). Now im trying to create a pivotviewer just with code and with version 5.

I took an example from the internet which is showing a sort of birthday book. The PivotViewerItemTemplate in that example is a simple border with a text box. Its all working fine but then i wanted to include an image file in the PivotViewerItemTemplate where the source tag is being bound to a string. Somehow i didnt get any picture till i manually placed through the toolbox another image just anywhere on the window. Now pivotviewer started to show that image for all objects it did get through the binding. I debugged and saw the binding is doing its correct work for all persons.

Mainpage.xaml

 <UserControl x:Class="PivotViewer5.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:pv="clr-namespace:System.Windows.Controls.Pivot;assembly=System.Windows.Controls.Pivot"
    xmlns:local="clr-namespace:PivotViewer5"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">


    <Grid x:Name="LayoutRoot" Background="White">
        <pv:PivotViewer x:Name="pivotviewer" ItemsSource="{Binding}">
            <pv:PivotViewer.PivotProperties>
                <pv:PivotViewerStringProperty Id="Name" Options="CanFilter" DisplayName="Name" Binding="{Binding Name}" />
                <pv:PivotViewerNumericProperty Id="Age" Options="CanFilter" DisplayName="Age" Binding="{Binding Age}" />
                <pv:PivotViewerDateTimeProperty Id="Birthday" Options="CanFilter" DisplayName="Birthday" Binding="{Binding Birthday}" />
            </pv:PivotViewer.PivotProperties>
            <pv:PivotViewer.ItemTemplates>
                <pv:PivotViewerItemTemplate MaxWidth="800">
                    <Border Width="120" Height="120" Background="DarkSlateBlue">
                        <Image Source="{Binding ImageName}" Width="120" Height="120"/>
                    </Border>
                </pv:PivotViewerItemTemplate>
                <pv:PivotViewerItemTemplate>
                    <Border Width="120" Height="120" Background="Blue">
                        <Image Source="{Binding ImageName}" Width="120" Height="120"/>
                    </Border>
                </pv:PivotViewerItemTemplate>
            </pv:PivotViewer.ItemTemplates>
        </pv:PivotViewer>
        <Image HorizontalAlignment="Left" Height="100" Margin="704,108,-404,0" VerticalAlignment="Top" Width="100" Source="images/bild.png" />
        <Image HorizontalAlignment="Left" Height="100" Margin="704,143,-404,0" VerticalAlignment="Top" Width="100" Source="images/bild4.png"/>
    </Grid>
</UserControl>

As you can see at the bottom i placed two images and after that pivotviewer started to accept image bild4 and bild. So "Brad" and "Rocky" now are being display with those images. After i removed the two image lines from the bottom, pivotviewer didnt show anything anymore except the borders and its background color.

MainPage.xaml.cs

public MainPage()
        {
            InitializeComponent();
            List<Person> birthdayBook = new List<Person>();
            birthdayBook.Add(new Person("Brad", 25, new DateTime(1986, 5, 9), "images/bild.png"));
            birthdayBook.Add(new Person("Janet", 12, new DateTime(1998, 12, 3), "images/bild3.png"));
            birthdayBook.Add(new Person("Rocky", 43, new DateTime(1968, 7, 17), "images/bild4.png"));
            birthdayBook.Add(new Person("Magenta", 21, new DateTime(1990, 2, 21), "images/bild.png"));

            pivotviewer.DataContext = birthdayBook;
}

I guess there is sth wrong in the xaml code in the ItemTemplate tag but where? Properties of bild (120x120), bild3 (485x485) and bild4 (120x120). Images are included in the project in that images folder, build action is Resource.

NitzerEbb
  • 1
  • 1

0 Answers0