michael nesterenko michael nesterenko - 23 days ago 16
C# Question

wpf card layout

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.

Answer

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];
    }
}