Hi,
I am stuck in multibinding and imultivalueconverter..
I am using IMultiValueConverter to convert value.
I have 1 button which I want to Enable Disable depending on textbox has text, combobox has selectedindex and anyone radio button checked from two radio button.
my problem is that when i select the male radio button then button is enable and when i select the female radio button then button is disable..
i want to enable button when textbox has text, combobox has selected index and anyone radio button is checked from male and female radio button.
Converter:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using System.Windows.Data;
using System.Globalization;
namespace WpfApplication4
{
public class FormFilledMultiConverter:IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
string name = values[0].ToString();
int selectedIndex = (int)values[1];
bool check = (bool)values[2];
bool isCheck = (bool)values[3];
return name.Length > 0 && selectedIndex != -1 && check || isCheck;
}
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
XAML :
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication4"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:FormFilledMultiConverter x:Key="FormFilledMultiConverter"/>
</Window.Resources>
<Grid>
<Label x:Name="labelName" Content="Name:" Margin="128,64,335,214"/>
<TextBox x:Name="textBoxName" Margin="204,64,164,231"/>
<Label x:Name="labelLetter" Content="Letter:" VerticalAlignment="Center" Margin="128,110,318,178" Height="31"/>
<ComboBox x:Name="comboBoxLetter" Margin="204,110,164,183" RenderTransformOrigin="1.706,1.583">
<ComboBoxItem Content="Alpha"/>
<ComboBoxItem Content="Beta"/>
<ComboBoxItem Content="Delta"/>
<ComboBoxItem Content="Gamma"/>
</ComboBox>
<Label Content="Gender" Width="57" HorizontalAlignment="Left" Margin="128,155,0,127"/>
<RadioButton GroupName="group" x:Name="rbtMale" Content="Male" Margin="204,166,252,127"/>
<RadioButton GroupName="group" x:Name="rbtFemale" Content="Female" Width="66" Margin="204,197,247,96"/>
<Button x:Name="buttonSubmit" Content="Submit" Margin="204,244,199,25">
<Button.IsEnabled>
<MultiBinding Converter="{StaticResource FormFilledMultiConverter}">
<Binding Path="Text" ElementName="textBoxName"/>
<Binding Path="SelectedIndex" ElementName="comboBoxLetter"/>
<Binding Path="IsChecked" ElementName="rbtMale"/>
<Binding Path="IsChecked" ElementName="rbtFemale"/>
</MultiBinding>
</Button.IsEnabled>
</Button>
</Grid>
</Window>