locked
help on pivot control RRS feed

  • Question

  • Hi,
    I'm new to the usage of Pivot control and looking for some quick help on the following:
    1. I have a Pivot page with multiple Pivot Items, what should be the event which I must handle to do some processing (like loading a list box in a Pivot Item with data) during the loading of a 'Pivot Item'. I was using the Loaded event  (PhoneApplicationPage_Loaded) for a normal Silverlight form application. What should be the equivalent for Pivot based form?
    2. How can I retrieve the 'Header' text of the newly selected 'Pivot Item', when the user selects a new 'Pivot Item'
    3. How can I dynamically select a 'Pivot Item'? I mean emulating the effect of user selecting a Pivot Item through code.
    4. How can I dynamically change the 'Header' text of a Pivot Item (Not statically by modifying XAML like this <controls:PivotItem> <controls:PivotItem.Header> <TextBlock Text="hello" Foreground="#FF79A545"/> </controls:PivotItem.Header>)
    5. How can I dynamically change the background image of a Pivot page?

    Appreciate any help.

    Also looking for pointers to some good reading materials on the usage of Pivot controls and sample Pivot control based Projects.

    Thanks
    Sunday, January 23, 2011 7:57 AM

Answers

  • Hi Shibu,

    1. I have a Pivot page with multiple Pivot Items, what should be the event which I must handle to do some processing (like loading a list box in a Pivot Item with data) during the loading of a 'Pivot Item'. I was using the Loaded event  (PhoneApplicationPage_Loaded) for a normal Silverlight form application. What should be the equivalent for Pivot based form?
    Pivot and PivotItem controls both have a Loaded event available.

    2. How can I retrieve the 'Header' text of the newly selected 'Pivot Item', when the user selects a new 'Pivot Item'
    You can do this (assuming you named your pivot "MyPivot"):
        string selectedHeader = (MyPivot.SelectedItem as PivotItem).Header as string;
    If you had defined your header as a TextBlock like in #4, cast it to a TextBlock instead of a string and access its Text property.
        TextBlock selectedHeader = (MyPivot.SelectedItem as PivotItem).Header as TextBlock;
        string selectedText = selectedHeader.Text;


    3. How can I dynamically select a 'Pivot Item'? I mean emulating the effect of user selecting a Pivot Item through code.
    Set the Pivot.SelectedIndex or Pivot.SelectedItem property (depending on whether you want to refer to an integer index or the PivotItem itself).

    4. How can I dynamically change the 'Header' text of a Pivot Item (Not statically by modifying XAML like this <controls:PivotItem> <controls:PivotItem.Header> <TextBlock Text="hello" Foreground="#FF79A545"/> </controls:PivotItem.Header>)
    Easiest thing to do here is give the TextBlock a name, like <TextBlock x:Name="MyHeader" Text="hello" Foreground="#FF79A545"/> , then you can directly access MyHeader.Text, MyHeader.Foreground, etc like any other TextBlock. Or you can access the Header through the PivotItem like I described in #2.
    5. How can I dynamically change the background image of a Pivot page?
    The Background property is a Brush. For an image, assign it an ImageBrush:
        ImageBrush img = new ImageBrush();
        BitmapImage bitmap = new BitmapImage(new Uri("/Background.png", UriKind.Relative));
        img.ImageSource = bitmap;
        MyPivot.Background = img;



    Richard
    Sunday, January 23, 2011 10:50 AM

All replies

  • Hi Shibu,

    1. I have a Pivot page with multiple Pivot Items, what should be the event which I must handle to do some processing (like loading a list box in a Pivot Item with data) during the loading of a 'Pivot Item'. I was using the Loaded event  (PhoneApplicationPage_Loaded) for a normal Silverlight form application. What should be the equivalent for Pivot based form?
    Pivot and PivotItem controls both have a Loaded event available.

    2. How can I retrieve the 'Header' text of the newly selected 'Pivot Item', when the user selects a new 'Pivot Item'
    You can do this (assuming you named your pivot "MyPivot"):
        string selectedHeader = (MyPivot.SelectedItem as PivotItem).Header as string;
    If you had defined your header as a TextBlock like in #4, cast it to a TextBlock instead of a string and access its Text property.
        TextBlock selectedHeader = (MyPivot.SelectedItem as PivotItem).Header as TextBlock;
        string selectedText = selectedHeader.Text;


    3. How can I dynamically select a 'Pivot Item'? I mean emulating the effect of user selecting a Pivot Item through code.
    Set the Pivot.SelectedIndex or Pivot.SelectedItem property (depending on whether you want to refer to an integer index or the PivotItem itself).

    4. How can I dynamically change the 'Header' text of a Pivot Item (Not statically by modifying XAML like this <controls:PivotItem> <controls:PivotItem.Header> <TextBlock Text="hello" Foreground="#FF79A545"/> </controls:PivotItem.Header>)
    Easiest thing to do here is give the TextBlock a name, like <TextBlock x:Name="MyHeader" Text="hello" Foreground="#FF79A545"/> , then you can directly access MyHeader.Text, MyHeader.Foreground, etc like any other TextBlock. Or you can access the Header through the PivotItem like I described in #2.
    5. How can I dynamically change the background image of a Pivot page?
    The Background property is a Brush. For an image, assign it an ImageBrush:
        ImageBrush img = new ImageBrush();
        BitmapImage bitmap = new BitmapImage(new Uri("/Background.png", UriKind.Relative));
        img.ImageSource = bitmap;
        MyPivot.Background = img;



    Richard
    Sunday, January 23, 2011 10:50 AM
  • Thanks Richard for the quick response. Awesome!
    Monday, January 24, 2011 6:31 AM