将文本 ( TextBox) 和图像 ( Image) 放在 aGrid中以创建所需的布局。调整大小将自动进行。
然后,将每个文本和图像的Visibility属性绑定到某个对象的属性,该属性存储在选项中选择的状态。(最好的解决方案是将此信息存储在您自己的某个新类中,并将该类的一个实例分配给您的窗口DataContext属性。
对于每个绑定,创建一个值转换器,该转换器返回Visibility.Visible或Visibility.Collapsed,具体取决于相应元素在当前选项下是可见还是不可见。
编辑:这是一些示例代码:
假设您非常简单的设置对象如下所示:
public enum GuiMode {
    FourTexts,
    ThreeTexts,
    OneText,
    ThreeTextsAndImage
}
public class GuiSettings : INotifyPropertyChanged
{
    public PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null) {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    private GuiMode mode = GuiMode.FourTexts;
    public GuiMode Mode {
        get {
            return mode;
        }
        set {
            if (mode != value) {
                switch (value) {
                    case GuiMode.FourTexts:
                    case GuiMode.ThreeTexts:
                    case GuiMode.OneText:
                    case GuiMode.ThreeTextsAndImage:
                        mode = value;
                        OnPropertyChanged("Mode");
                        break;
                    default:
                        throw new InvalidEnumArgumentException("value", (int)value, typeof(GuiMode));
                }
            }
        }
    }
}
这存储了您的 GUI 的模式。注意 的实现INotifyPropertyChanged,因此当绑定到Mode属性时,属性的更改Mode将自动更新绑定到它的任何内容。
然后,例如,对于text2,您可以编写以下值转换器:
public class Text2VisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        switch ((GuiMode)value) {
            case GuiMode.OneText:
                return Visibility.Collapsed;
            default:
                return Visibility.Visible;
        }
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotSupportedException("This converter does not convert back.");
    }
}
由于text2始终可见,除了只显示一个文本时的状态 - GuiMode.OneText- ,相应的Visibility值由转换器返回。另请注意,此转换器仅假定传入value的是一个GuiMode值。要正确执行此操作,您应该检查您所获得的内容value以及targetType.
完成此操作后,您可以将转换器作为静态资源导入 Xaml:
<Window.Resources>
    <Text2VisibilityConverter x:Key="text2vis"/>
</Window.Resources>
根据您导入的命名空间,您可能需要在前面添加适当的命名空间前缀Text2VisibilityConverter。
然后可以使用将text2的Visibility属性绑定到类中的属性,假设您存储设置的实例已分配给窗口的属性:ModeGuiSettingsText2VisibilityConverterGuiSettingsDataContext
<TextBlock Text="Text 2" Visibility="{Binding Mode, Converter={StaticResource text2vis}}"/>
一旦成功,您可以为其他控件的可见性添加更多值转换器类。