0

Im trying to use multibinding as i have two textboxes to validate for Text.Length.

Here is my code.

<StackPanel HorizontalAlignment="Left" Height="28" Margin="107,238,0,0" VerticalAlignment="Top" Width="104" Orientation="Horizontal" Grid.Column="1"> <Button x:Name="btnAddBenefeciary" Content="Add Beneficiary" HorizontalAlignment="Left" VerticalAlignment="Top" Width="99" RenderTransformOrigin="0.587,0.65" Height="28" Click="btnAddBenefeciary_Click"> <Button.IsEnabled> <MultiBinding Converter="{StaticResource IsEnabledConverter}"> <Binding ElementName="tbFatherName" Path="Text.Length"/> <Binding ElementName="tbFatherName" Path="Text.Length" /> </MultiBinding> </Button.IsEnabled> </Button> </StackPanel> 

In the Same File i added this line under <Window.Resources>

<local:IsEnabledConverter x:Key="IsEnabledConverter" /> 

But i am not sure where to put this piece of code so i did put in its own xaml.cs file of which this window belongs.

public class IsEnabledConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { foreach (var isValid in values) if (isValid as bool? == false) return false; return true; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } 

Did i needed to create another file or is it fine to use this piece of code in this same file as no one said anything in description of creating new file..

I tried to follow these guide lines.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/5b9cd042-cacb-4aaa-9e17-2d615c44ee22/can-i-bind-a-controls-isenabled-to-the-selectedindex-of-one-or-more-comboboxes?forum=wpf

http://developingfor.net/2009/01/21/multibinding-in-wpf/

Making a Button IsEnabled state depend on two textboxes

So if i have to create new file, how will i reference this to the new file.. Sorry again as i am new to WPF and .NET.

=-=-=-=-=-=-=-=-=

Did changes as per described in answer but getting new errors..

enter image description here

=-=-=-=-=-=-=-

Update 2:

Tried like this..

enter image description here

2 Answers 2

0

The converter class can be in any folder/file you want, the namespace of the converter is important. But it's a good habit to put converters - and any classes for that mather - in seperate files called the same as the class their contain. And putting converter classes in a seperate "Converters" folder. As how to reference it, you need to declare the namespace of the converter in your xaml file where you want to use it:

<Window .... xmlns:converters="clr-namespace:YourProject.ConvertersNamespace" .... > 

Then you can reference the converter class in the resources:

<converters:IsEnabledConverter x:Key="IsEnabledConverter" /> 

And then use the converter in you multi binding as you described. Altough you have in your multibinding two identical bindings to the tbFatherName element name, but I guess that's just a typo.

Sign up to request clarification or add additional context in comments.

6 Comments

Thankyou for reply sir, Added like this xmlns:converters="clr-namespace:RMS.IsEnabledConverter" But i am getting error of could not found.. I did created a folder named 'Converters and create a new Class file named IsEnabledConverter'
If you created such folder, most probarly the namespace would be 'xmlns:converters="clr-namespace:RMS.Converters.IsEnabledConverter"' please look at the namespace where the IsEnabledConverter class resides
i moved it outside of folder, thought as it might be fixed. but still the same issue.. i have updated the question with screen shot.
Didn't noticed that you have added the class name to the namespace definition, it should be: "'xmlns:converters="clr-namespace:RMS.Converters" - you really nead firstly learn "C#" because after this issue you will get a lot o new ones without the basics of C#
xD. Thats the idea.. But for the this project sake i really need help. As My Boss wants to Finish it ASAP. Added The ScreenShot for another Update. Another Line Started Giving Error.
|
0

Content="Confirm" Grid.Column="1" HorizontalAlignment="Left" Margin="10,160,0,0"

Grid.Row="1" VerticalAlignment="Top" Height="27" Width="80">

 <Button.CommandParameter> <MultiBinding Converter="{StaticResource CustomMultiValueConverterKey}"> <Binding ElementName="cboCountry" Path="SelectedValue"/> <Binding ElementName="cboShopKeeperID" Path="SelectedValue"/> </MultiBinding> </Button.CommandParameter> </Button> 

and the back have to write

CommonControlHandlers.populateControls("CALL GetCountryList()", cboCountry);

 CommonControlHandlers.populateControls<ComboBox>("CALL GetShopKeeperList()", cboShopKeeperID); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.