This might help:
XAML:
<window x:class="TextBoxVisibility.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TextBoxVisibility"
Title="MainWindow" Height="350" Width="525">
<window.resources>
<local:viewmodel x:key="ViewModelClass" xmlns:local="#unknown" />
<local:converter x:key="Converter" xmlns:local="#unknown" />
</window.resources>
<window.datacontext>
<binding source="{StaticResource ViewModelClass}" />
</window.datacontext>
<grid>
<grid.columndefinitions>
<columndefinition width="Auto" />
<columndefinition width="*" />
</grid.columndefinitions>
<grid.rowdefinitions>
<rowdefinition height="Auto" />
<rowdefinition height="Auto" />
<rowdefinition height="Auto" />
</grid.rowdefinitions>
<label content="FirstTextBox" />
<label content="SecondTextBox" grid.row="1" />
<textbox x:name="txt1" text="{Binding Path=Condition,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" grid.column="1" />
<textbox x:name="txt2" visibility="{Binding Path=IsVisible, Mode=TwoWay, Converter={StaticResource Converter}}" grid.column="1" grid.row="1" />
</grid>
</window>
ViewModel:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace TextBoxVisibility
{
public class ViewModel : INotifyPropertyChanged
{
public ViewModel()
{
isVisible = false;
condition = 0;
}
private bool isVisible;
private int condition;
public int Condition
{
get
{
return condition;
}
set
{
condition = value;
this.OnPropertyChanged("Condition");
this.OnPropertyChanged("IsVisible");
}
}
public bool IsVisible
{
get
{
GetConditon();
return isVisible;
}
set
{
isVisible = value; ;
this.OnPropertyChanged("IsVisible");
}
}
private void GetConditon()
{
isVisible=condition > 20;
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
Converter:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
namespace TextBoxVisibility
{
public class Converter :IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
bool isVisible = (bool)value;
return isVisible ? Visibility.Visible : Visibility.Hidden;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}