WPF: Binding help

WPF: Binding help

Old forum URL: forums.lhotka.net/forums/t/5607.aspx


ajj3085 posted on Thursday, October 16, 2008

Hi,

I have a user control (PartEdit) which will contain another user control (purchase history).  The part edit includes the purchase history control in this manner:

<invwpf:PurchaseHistoryView Part="{Binding Source={StaticResource PartData}, Path=Data}" />

Where PartData is a CslaDataProvider resource in PartEdit, and the Data will be the Part business object.  Part on PurchaseHistoryView is a dependency property:

        public static readonly DependencyProperty PartProperty =
            DependencyProperty.Register(
                "Part",
                typeof( Part ),
                typeof( PurchaseHistoryView ),
                new PropertyMetadata( PartPropertyChanged )
            );

The PartPropertyChanged never seems to be called.. so I'm guessing the binding isn't working for some reason... but I don't see any binding errors in the Output window.  I've also tried adding a "BindsDirectlyToSource" but that doesn't seem to make a difference.

Any ideas?

Thanks
Andy

cclark replied on Thursday, October 16, 2008

You might try adding in a coerce value callback to see what value if any you get:

public static readonly DependencyProperty SmartValueProperty = DependencyProperty.Register("SmartValue",

typeof(object), typeof(SmartCombo), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,

new PropertyChangedCallback(OnSelectedValueChanged), new CoerceValueCallback(CoerceSelectedValue)));

Note that sometimes null values invalidate bindings.

ajj3085 replied on Friday, October 17, 2008

Hmm, I may try that.   I did add a ValidationCallback that always returned true... and it never got called either.  For now I've just added some code in the DataProviders DataChanged event handler.  But it would be nice to have it in xaml.

vschuhma replied on Friday, October 17, 2008

Hi Andy,

 

just a stupid question. Did you use the SetValue(PartProperty) on your set?

Best Regards

Volker

ajj3085 replied on Friday, October 17, 2008

Yes, but databinding doesn't appear to call the property set I've defined, I believe it calls SetValue directly.. which is why you're not supposed to do any other code in the property setter you create for the instance.

Copyright (c) Marimer LLC