This is a migrated thread and some comments may be shown as answers.

Binding DependencyProperty when invisible?

1 Answer 19 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Jeff asked on 28 Dec 2015, 08:23 PM

I have a WPF window that contains a Telerik RadPaneGroup, and in it I have a RadPanes:

        CanFloat="{Binding preferencesProperties.canFloatPanes}"
        IsHidden="{Binding Path=viewModel.stickyProperties.mapPaneVisible, RelativeSource={RelativeSource AncestorType=KtWpf:KorWindow}, Mode=TwoWay, Converter={StaticResource boolInverterConverter}}"
        ticketMapType="{Binding RelativeSource={RelativeSource AncestorType=KtWpf:KorWindow}, Path=viewModel.preferencesProperties.ticketMapType}"

The ticketMapPane.IsHidden property is bound to the negation of stickyProperties.mapPaneVisible, so if mapPaneVisible is true, IsHidden is false, and the pane is displayed.

If mapPaneVisible is true on startup, ticketMapPane is visible, and ticketMap.ticketMapType is bound correctly to preferencesProperties.ticketMapType, and all is well with the world.

If I then manipulate the UI control that sets stickyProperties.mapPaneVisible to false the pane becomes invisible, if I set it to true the pane becomes visible again, and ticketMapType is bound correctly through it all.

But if stickyProperties.mapPaneVisible is false on startup, ticketMapPane is hidden, and ticketMapType doesn't seem to be bound.
I have a change handler on the ticketMapType property. It's called, when the ticketMapPane is visible on startup, and it is not, when it is not:

public partial class TicketMap : KorUserControl
    public TicketMapType ticketMapType
        get { return (TicketMapType)GetValue(ticketMapTypeProperty); }
        set { SetValue(ticketMapTypeProperty, value); }
    public static readonly DependencyProperty ticketMapTypeProperty =
        DependencyProperty.Register("ticketMapType", typeof(TicketMapType), typeof(TicketMap),
        new PropertyMetadata(new PropertyChangedCallback(ticketMapTypePropertyChanged)));
    private static void ticketMapTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        var ticketMap = d as TicketMap;
        if (ticketMap != null && e.NewValue is TicketMapType)
            var ticketMapType = (TicketMapType) e.NewValue;

So what is happening is that if the pane is hidden on startup, when I make it visible the TicketMap.ticketMapType contains the default value, and not the value that it was supposed to be bound to. If the pane is visible on startup, everything binds correctly.

So, the question - how do I get this to work?

 I can see two possibilities:

  1. I get the binding to connect even though the pane is invisible, or
  2. I get the binding to connect when the pane is made visible.

Any ideas as to how to do either?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 29 Dec 2015, 12:16 PM
Hello Jeffrey,

Using the provided description we tried to reproduce the observed by you behavior - we created a custom control with a dependency property and placed it inside a Pane whose IsHidden property was set to true. When the Pane became visible the binding of the dependency property worked as expected and the property was initialized with the desired value - the unexpected behavior on your side is probably caused due to some custom implementation. Attached you could find a video that demonstrates how the described above approach worked on our side - please, check it and let us know if we didn't miss something.

Could you please, try to create a sample that demonstrates the observed issue, as it seems you have too custom logic implemented in your project and it will be hard for us to reproduce it on our side using the provided code snippets - thus we could also continue our investigation and provide you with a prompt solution?

Looking forward for your reply.

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question