Multibinding

Apr 14, 2009 at 10:02 AM
Edited Apr 14, 2009 at 10:49 AM
First off, thanks for the cool set of controls. I have been working on an audio app and these controls have been very useful.
One of the controls I am working on is a audio pan knob. Its based on knob360. The goal is, the position of the knob needs to control 2 data values, and conversely the 2 data values control the position of the knob. So basically, I am trying to get twoway multibinding to work with the knob.

Whats happening is everytime I move the knob the multiconverters ConvertBack() gets called (as it should) and the knob value is translated in to 2 values (eg: knob value=25 => data1=0 data2=25), but at this point something weird happens, ValuePropertyChanged is getting called twice with 25 first and then 0 and knob moves to 25 and then to 0. Any ideas on why this is happening? Thanks!

This may have nothing to do with the issue, but why is there a value dependancy property and a value property defined?

This is what things look like xaml + multi converter:

 <local:Knob Grid.Row="0" Grid.Column="0" IsBidirectional="True" >
    <local:Knob.Value>
        <MultiBinding Converter="{StaticResource convertpan}" Mode="TwoWay" >
            
<MultiBinding.Bindings>
                
<Binding Path="Contrl[0].Value" />
                
<Binding Path="Contrl[1].Value" />
            
</MultiBinding.Bindings>
        
</MultiBinding>
    
</local:Knob.Value>
</local:Knob>

 

 

public class ConvertPan : IMultiValueConverter
{
    
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        
float i1 = (float)(values[0]);
        
float i2 = (float)(values[1]);
        
if (i1 == 0 && i2 == 0)
            
return 0.0;
        
if (i1 == 0 && i2 < 0)
            
return -1.0 * i2;
        
if (i2 == 0 && i1 < 0)
            
return i1;
        
return 0.0;
}

 

 

 

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    float tmp = System.Convert.ToSingle(value);
    
float[] ret = new float[2]{0.0f,0.0f};
    
if (tmp > 0)
    {
        ret[0] = 0.0F;
        ret[1] = tmp;
    }
    
if (tmp < 0)
    {
        ret[0] = tmp;
        ret[1] = 0.0F;
    }
    
object[] o1dim = new object[ret.Length];
    
Array.Copy(ret, o1dim, ret.Length);
    
return o1dim;
}

 

 

 

 

Coordinator
Apr 14, 2009 at 1:38 PM
Are you running off the top of tree code or the last release? I seem to recollect that this issue happened a while back and I put a fix in. There hasn't been a release for a while as I keep finding issues with WPF compatability and I am trying to get everything working on both platforms before I release again.

If you are building from top of tree then I will have a look at this. I have to confess I have not used a multibinding yet in testing.

I will have a chance to look at this, this week end comming.

D