locked
Botton click event to bring up user control RRS feed

  • Question

  • Hello,
    I need your help please.

    I am using the following:
    1. Silverlight 2.0
    2. Expression Blend 2.5
    3. Visual Studio 2008

    I've created the Following:
    1. A SilverLight app. containing bottons and a border control.
    2. A few slightly differant user controls in the form of grid containing various user controls. They are meant to replace one another.

    In the app I want each botton's click event to add the appropriate user control in the same border on my app. (same as the bottons 'Day' Week' etc... in outlook calendar).

    Questions:
    1. How do I define the click event for the bottons so that with each click the border will contain the user control of my choice replacing the previous one?
    2. How do I define the chosen control to override the previous?

    Thanks a lot,
    DrorSter

    Saturday, July 12, 2008 1:45 AM

Answers

  •  I think it's just like a navigation

    XAML

    <StackPanel Height="400" Width="280" Orientation="Vertical">
    <StackPanel Height="50" Width="280" Orientation="Horizontal">
        <Button Width="70" Content="Btn1" Click="Btn1_Click" />
        <Button Width="70" Content="Btn2" Click="Btn2_Click" />
        <Button Width="70" Content="Btn3" Click="Btn3_Click" />
        <Button Width="70" Content="Btn4" Click="Btn4_Click" />
    </StackPanel>
    <StackPanel x:Name="_Content" Height="350" Width="280" Orientation="Horizontal"/>
    </StackPanel>

     C#, Let say you have four UserControl defined

    SilverlightUserConrtol1 page1 = new SilverlightUserConrtol1();

            void Btn1_Click(object sender, RoutedEventArgs e)
            {
                if (_Content.Children.Count() != 0) _Content.Children.RemoveAt(0);
                _Content.Children.Add(page1);
            }

    And Similar for the others Click

    Saturday, July 12, 2008 2:40 AM