Here's a sample using MVVM that avoids codebehind (debatable MVVM no-no):
<UserControl>
<StackPanel>
<ComboBox x:Name="comboBox" SelectionChanged="comboBox_SelectionChanged"/>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsFirstFormShown}">
<TextBlock Text="First: "/>
<TextBox/>
</StackPanel>
<StackPanel Orientation="Horizontal" Visibility="{Binding IsSecondFormShown}">
<TextBlock Text="Second: "/>
<TextBox/>
</StackPanel>
</StackPanel>
</UserControl>
Here's your ViewModel then,
public class MyFormViewModel : INotifyPropertyChanged
{
private System.Windows.Visibility _isFirstShown;
public System.Windows.Visibility IsFirstFormShown
{
get { return _isFirstShown; }
set
{
_isFirstShown = value;
if (PropertyChanged != null )
{
PropertyChanged(this, new PropertyChangedEventArgs(value));
}
}
}
//TODO: implement the other property (writing code in this edit window makes me tired)
//hopefully you get the picture here...
}
Pretty simple. I'd probably try and name my properties something a little more "Model" and less "View", but this convention is not entirely inappropriate.