创建转换器非常简单。
有类似的东西:
using System.Globalization;
using System.Windows;
using System.Windows.Data;
public class ResizeModeConverter : IValueConverter {
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
return (bool)value ? ResizeMode.CanResize : ResizeMode.CanMinimize;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
throw new NotImplementedException();
}
}
并将此转换器添加到您的 App.xaml 资源中(转换器应该在您的可用范围内Window
)
<Application.Resources>
<local:ResizeModeConverter x:Key="ResizeModeConverter" />
</Application.Resources>
现在在你的Window
<Window ... ResizeMode="{Binding SomeProperty, Converter={StaticResource ResizeModeConverter}}">
现在,当SomeProperty
设置为 true 或 false 时,您将获得所需的行为。您可以在读取本地设置后在启动时在 VM 中设置该属性,或者在运行时对其进行修改,一切都应该没问题。