Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlinks are staying inactive after setting isEnabled=true to parent control

I've got a TabItem contanining a listbox, which has an obeservable collection of my feeds class as its item source. When I refresh/load the feeds into the collection I want to disable the main window so that the user can't go clicking other things while this process is running. So I set tbCtrl.isEnabled=false; to my tab control on the form. Then assign an event handler to the a custom finish event which is triggered after all the feeds are loaded.

This all works fine, however the hyperlinks for the results which are currently displayed on the tab control never get re-enabled (Nor do the next few which are out of view due to the list box size). All the other results further down are fine, as are the results on the other tab.

I've tried calling InvalidateVisual on the tab control after everything is finished, to see if that makes a difference but that doesn't seem to cause any change.

I could understand it if it was all Hyperlinks doing it, or just the ones currently displayed, but I don't understand why ones which are out of scroll are not working either.

Image of Issue

like image 448
Psytronic Avatar asked Mar 23 '10 11:03

Psytronic


2 Answers

I hit the same issue.

What I did is to bind HyperLink's IsEnabled to the parent, and put that in an App global resource.

<Style TargetType="{x:Type Hyperlink}">
    <Setter Property="IsEnabled" Value="{Binding IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FrameworkElement}}}" />
</Style>
like image 75
HelloSam Avatar answered Sep 19 '22 18:09

HelloSam


I found the answer for my case of the hyperlink not getting re-enabled, not sure if it applies to yours:

I found that when the Hyperlink's parent control is disabled (IsEnabled=false), the Hyperlink will not get notified of changes, e.g. IsEnabledChanged does not get fired, even when the bound property changes value.

My solution was to change my Xaml to no longer disable the ancestor control (which was causing the Hyperlink's parent to be disabled). With the parent (TextBlock) always enabled, now Hyperlink updates properly always.

(I'm a little bothered that the IsEnabled binding behaves differently than Controls do, and I'm not sure what I would do if I couldn't leave the ancestor enabled... but at least this lets me understand the issue I was having, and lets me work around it.)

Details: WPF 3.5 SP1

like image 33
Daryn Avatar answered Sep 18 '22 18:09

Daryn