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.
Asked
Active
Viewed 5,914 times
6
-
Could you please provide a sample? – Fischermaen Oct 25 '11 at 06:59
-
@Fischermaen, http://download.oracle.com/javase/tutorialJWS/uiswing/layout/ex6/CardLayoutDemo.jnlp – michael nesterenko Oct 25 '11 at 07:17
-
I am not a java developer - just a simple screenshot showing the desing you want would be sufficient. – Fischermaen Oct 25 '11 at 07:27
-
@Fischermaen, http://download.oracle.com/javase/tutorial/uiswing/layout/card.html – michael nesterenko Oct 25 '11 at 07:30
1 Answers
4
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];
}
}

fardjad
- 20,031
- 6
- 53
- 68
-
1I know it's old but appears first in Google for 'CardLayout WPF': there is also `TabControl` which is really, really useful (at least for me). – mwilczynski Aug 17 '14 at 20:08