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

3

14

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

Jasper answered 23/3, 2010 at 11:26 Comment(2)
I am looking for an answer to the same issue. I've bound the Hyperlink.IsEnabled to a property with INotifyPropertyChanged. When I invoke the change one way, IsEnabled updates. Another way, it doesn't. (Both are threads) -- But a button with the same binding does get its IsEnabled changed. All I'm left with is a vague guess that it's something to do with flow document acting different than a control, but not sure why? Weirdest thing: If I set the Hyperlink binding to IsEnabled="{Binding ElementName=AControlWithIsEnabledBinding, Path=IsEnabled}", it WORKS!. But how much of a hack is that, eh?Sargasso
Just a note, this issue appears to be fixed as of .NET 4.6.1. This is important to keep in mind if you are developing in a 4.6.1+ environment but targeting lower .NET versions, as hyperlink enabled states will appear to work fine for you, but if someone with a lower .NET version runs your app, they will run into this issue.Devland
S
6

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

Sargasso answered 14/12, 2010 at 23:40 Comment(0)
T
14

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>
Tade answered 2/6, 2011 at 14:11 Comment(3)
if you explicitly put IsEnabled on the HyperLink itself and bind it to something that will override this global resource right?Ermeena
@Ermeena Yes. See msdn.microsoft.com/en-us/library/ms743230(v=vs.110).aspx. Style is 6th, setting explicitly is 3rd and has a higher precedenceTade
Life saver, thanks! P.S. Да что вы знаете о сказочных мирах, да майкрософт?Overstate
S
6

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

Sargasso answered 14/12, 2010 at 23:40 Comment(0)
E
0

It's not just HyperLinks. It seems to be more specifically TextBlock which of course is what you use to wrap a HyperLink in WPF. This will give the same issue :

<TextBlock>
    <Run Text="Barcode:"/>
    <InlineUIContainer BaselineAlignment="Center">
        <TextBox Text="{Binding OriginalPackage.BarcodeNumber}" />
    </InlineUIContainer>
</TextBlock>

I was hoping setting IsEnabled="True" would fix it but it doesn't seem to.

The easy solution is to use a StackPanel with Orientation="Horizontal"

Ermeena answered 17/10, 2012 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.