我对 MVVM 技术很陌生,似乎无法在任何地方找到我的问题的答案。有人可以给我一个详细的例子来说明如何让它工作。我正在尝试单击按钮以显示一个文本框。
到目前为止我有这个。WPF
<TextBox Visibility="{Binding IsVisibleBoolean, Converter={StaticResource boolToVis}}"
Height="23" HorizontalAlignment="Left" Margin="340,439,0,0" Name="textBox2" VerticalAlignment="Top" Width="180" />
<Button Command="{Binding IsVisibleBoolean}" Height="32" Margin="526,401,142,0" Name="button2" VerticalAlignment="Top" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"/>
C# 视图模型
private bool _isVisibleBoolean = false;
public bool IsVisibleBoolean
{
get { return _isVisibleBoolean; }
set
{
if (_isVisibleBoolean == value)
return;
_isVisibleBoolean = value;
RaisePropertyChanged("IsVisibleBoolean");
}
}
和我的 booleanconvert 类
public class BooleanToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value is Boolean)
{
return ((bool)value) ? Visibility.Visible : Visibility.Collapsed;
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}
任何帮助都会很棒。