0
votes

I am trying to use a single IMultiValueConverter for more than one controls in XAML.

I am using a simple string Literal to tell what value the IMultiValueConverter is supposed to return.

But I am getting DependencyProperty.UnsetValue in values[2],ie value of parametter named Command when it comes to convert function of ModifierCategoryEnableDisable.

Similar arrangment is working on similar controls on this XAML form within other IMultiValueConverters but not here. Please guide what am i missing?

NOTE:

  1. CurrentRec is the currently selected object from the ViewModel
  2. DM_CategoryData is a Class and Current_Selected_Category is a List<DM_CategoryData> in the ViewModel's current object,ie CurrenRec.

XAML:

<GroupBox Width="226" Height="117"  Margin="0" Canvas.Top="252" Header="Modifiers" Canvas.Left="55" >
         <GroupBox.IsEnabled>
             <MultiBinding Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" Converter="{StaticResource MDNS}">
                     <Binding Path="SearchFound" />
                     <Binding Path="CurrentRec.Current_Selected_Category"/>
                     <Binding Path="Command" FallbackValue="1" />
              </MultiBinding>
        </GroupBox.IsEnabled>
 </GroupBox>

C#:

public class ModifierCategoryEnableDisable : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        string Command = values[2].ToString();
        bool Retval1 = false;
        string Retval2 = "";
        switch(Command)
        {
            case "1":
                bool SearchFound = (bool)values[0];
                DM_CategoryData CurrentSelectedItemCategory = (DM_CategoryData)(values[1]);
                Retval1 = SearchFound && (CurrentSelectedItemCategory == null ? true : CurrentSelectedItemCategory.IsModifier.Equals("1") ? false : true);
                break;
            case "2":
                Retval2 = "0";
                break;
        }               

        if(Command.Equals("1"))
        {
            return Retval1;
        }
        else
        {
            return Retval2;
        }
   }
}
2
So you expect "0" to be converted to boolean implicitely after the converter finished? Did you check the output window in visual studio for binding errors and exceptions? Did you debug the converter (breakpoint and single steps)?grek40
Noooo.zas i said ,this converter is to be used at various places in the code and this converter is going to return multiple values.At one poitn it is siupposed to return a boolean while it is supposed to return a string in another.I can do that if i can somehow tell the converter what to do with the incomming values and then return the approporate object,but only i am able to resolve the DedpendencyProperty.Unset value.Jatinder Walia

2 Answers

1
votes

In order to provide additional static data to a multibinding converter, use a ConverterParameter:

<MultiBinding Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" Converter="{StaticResource MDNS}" ConverterParameter="1">
    <Binding Path="SearchFound" />
    <Binding Path="CurrentRec.Current_Selected_Category"/>
</MultiBinding>

And check the parameter in the Convert method:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
    string Command = parameter as string;

    // ...
}
-1
votes

You are trying to set the fallbackvalue for GroupBox.IsEnabled property and it is a bool type. But you are setting the value as 1. So only Values[2] returns the UnsetValue. Try to set bool value as Fallbackvalue.