Dziękuje panowie za pomoc. Poniżej w pełni działający kod:
xaml:
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<local:MultiValueConverter x:Key="MultiValueConverter" />
</Window.Resources>
<Grid>
<Canvas x:Name="myCanvas" HorizontalAlignment="Left" Height="225" Margin="70,70,0,0" VerticalAlignment="Top" Width="595">
<TextBox x:Name="tb1" Text="{Binding TextOne, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="24" Canvas.Left="35" TextWrapping="Wrap" Canvas.Top="36" Width="120"/>
<TextBox x:Name="tb2" Text="{Binding TextTwo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="23" Canvas.Left="200" TextWrapping="Wrap" Canvas.Top="37" Width="120"/>
<TextBox x:Name="tb3" Text="{Binding TextThree, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="23" Canvas.Left="375" TextWrapping="Wrap" Canvas.Top="36" Width="120"/>
<Button x:Name="btn1" Content="Button1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Canvas.Left="80" Canvas.Top="155">
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource MultiValueConverter}">
<Binding Path="TextOne" />
<Binding Path="TextTwo" />
<Binding Path="TextThree" />
</MultiBinding>
</Button.IsEnabled>
</Button>
<Label x:Name="lbl1" Content="Label" Canvas.Left="80" Canvas.Top="105"/>
</Canvas>
</Grid>
</Window>
MultiValueConverter:
public class MultiValueConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string one = values[0] as string;
string two = values[1] as string;
string three = values[2] as string;
if (!string.IsNullOrEmpty(one) && !string.IsNullOrEmpty(two) && !string.IsNullOrEmpty(three))
return true;
return false;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
DataContext class:
namespace WpfApp1
{
public class MainViewModel : INotifyPropertyChanged
{
public MainViewModel()
{
}
public event PropertyChangedEventHandler PropertyChanged;
private string _textOne;
public string TextOne
{
get { return _textOne; }
set
{
_textOne = value;
NotifyPropertyOnChange(nameof(TextOne));
}
}
private string _textTwo;
public string TextTwo
{
get { return _textTwo; }
set
{
_textTwo = value;
NotifyPropertyOnChange(nameof(TextTwo));
}
}
private string _textThree;
public string TextThree
{
get { return _textThree; }
set
{
_textThree = value;
NotifyPropertyOnChange(nameof(TextThree));
}
}
public void NotifyPropertyOnChange(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Bindowanie DataContextu:
public MainWindow()
{
InitializeComponent();
this.DataContext = new MainViewModel();
}