Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Use Multi binding for passwordbox and radiobutton

$
0
0

i want to use multibinding for button is enabled when textbox and passwordbox are not empty

Converter:

public class FormFilledConverter:IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            string addrs = values[0].ToString();
            string fullName = values[1].ToString();
            string cty = values[2].ToString();
            string pwd = values[3].ToString();
            string conpwd = values[4].ToString();
           bool rm = (bool)values[5];
            bool rf = (bool)values[6];
            bool isAnyChecked = rm || rf;

            return addrs.Length != 0 && isAnyChecked  && fullName.Length != 0 && cty.Length != 0 && pwd.Length != 0 && conpwd.Length != 0;
        }
        public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

Admin.xaml

 <TextBox x:Name="txtAddress" Margin="0" FontFamily="Times New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="100"/>
<TextBox x:Name="txtFullName" Margin="0,1,0,0" FontFamily="Times New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="19"/>

<TextBox x:Name="txtCity"  Margin="0,1,0,0" FontFamily="Times New Roman" FontSize="14" FontStyle="Normal" FontWeight="Normal" Height="19"/>

<PasswordBox x:Name="Pwd" HorizontalAlignment="Left"
                    VerticalAlignment="Top" Grid.Column="3" Grid.Row="3" Width="137" Height="21" Margin="0" FontSize="14" />
 <PasswordBox x:Name="ConPwd" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="3" Grid.Row="5" Width="137" Height="19" FontWeight="Normal" FontFamily="Times New Roman" FontSize="14" Margin="0,1,0,0"/>
<RadioButton x:Name="rbtMale" Content="Male" Grid.Column="2" Grid.Row="1" FontFamily="Times New Roman" FontSize="14" FontStyle="Normal" Margin="0,0,113,0" Foreground="White"/>
<RadioButton x:Name="rbtFemale" FontStyle="Normal" FontFamily="Times New Roman" FontSize="14" Grid.Column="2" Margin="63,0,41,0" Grid.Row="1" Content="Female" Foreground="White"/>

<Button x:Name="btnAddAdmin" Style="{StaticResource ButtonStyleTemplate}" Grid.Column="3" Margin="5,0" Content="Add" FontFamily="TimesNewRoman">
                    <Button.IsEnabled>
                        <MultiBinding Converter="{StaticResource FormFilledConverter}">
                            <Binding Path="Text" ElementName="txtAddress"/>
                            <Binding Path="Text" ElementName="txtFullName"/>
                            <Binding Path="Text" ElementName="txtCity"/>
                            <Binding Path="Password" ElementName="Pwd"/>
                            <Binding Path="Password" ElementName="ConPwd"/>

                            <Binding Path="IsChecked" ElementName="rbtMale"/>
                            <Binding Path="IsChecked" ElementName="rbtFemale"/>                                          </MultiBinding>
                    </Button.IsEnabled>
                </Button>


























Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>