Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf card layout

Tags:

c#

layout

wpf

I am very new to wpf. How can I implement CardLayout functionality from java? I have a window where I need completely switch contents depending on user actions, like different tabs in tabbed pane.

like image 558
michael nesterenko Avatar asked Oct 25 '11 06:10

michael nesterenko


1 Answers

You can create multiple pages and host them in a frame. Look here for more information.

XAML:

<Window x:Class="CardLayout"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="CardLayout" Height="300" Width="300">
    <Grid>
        <Frame Height="200" HorizontalAlignment="Left" Margin="12,40,0,0" Name="frame1" VerticalAlignment="Top" Width="254" NavigationUIVisibility="Hidden" />

        <ComboBox HorizontalAlignment="Left" Margin="12,12,0,0" Name="comboBox1" VerticalAlignment="Top" Width="254" SelectedIndex="0" SelectionChanged="comboBox1_SelectionChanged">
            <ComboBoxItem>FirstPage</ComboBoxItem>
            <ComboBoxItem>SecondPage</ComboBoxItem>
        </ComboBox>
    </Grid>
</Window>

Code Behind:

public partial class CardLayout : Window
{
    private Page[] pages = new Page[] {new Page1(), new Page2()};

    public CardLayout()
    {
        InitializeComponent();
    }

    private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        frame1.Content = pages[((ComboBox) sender).SelectedIndex];
    }
}
like image 153
fardjad Avatar answered Oct 17 '22 13:10

fardjad