将 isEnabled=true 设置为父控件后,超链接保持非活动状态

发布于 2024-08-25 19:29:47 字数 571 浏览 12 评论 0原文

我有一个包含列表框的 TabItem,其中有我的 feeds 类的可观察集合作为其项目源。当我刷新/将提要加载到集合中时,我想禁用主窗口,以便用户在此进程运行时无法单击其他内容。因此,我将 tbCtrl.isEnabled=false; 设置为表单上的选项卡控件。然后将事件处理程序分配给自定义完成事件,该事件在加载所有提要后触发。

这一切都工作正常,但是当前显示在选项卡控件上的结果的超链接永远不会重新启用(接下来的几个由于列表框大小而无法查看的超链接也不会重新启用)。下面的所有其他结果都很好,其他选项卡上的结果也是如此。

我尝试在一切完成后在选项卡控件上调用 InvalidateVisual ,看看这是否会产生影响,但这似乎不会导致任何变化。

如果是所有超链接,或者只是当前显示的超链接,我可以理解它,但我不明白为什么那些不滚动的链接也不起作用。

图片问题

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清引 2024-09-01 19:29:47

我遇到了同样的问题。

我所做的是将 HyperLink 的 IsEnabled 绑定到父级,并将其放入应用程序全局资源中。

<Style TargetType="{x:Type Hyperlink}">
    <Setter Property="IsEnabled" Value="{Binding IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type FrameworkElement}}}" />
</Style>

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>
肥爪爪 2024-09-01 19:29:47

我找到了超链接未重新启用的情况的答案,不确定它是否适用于您的情况:

我发现当超链接的父控件被禁用(IsEnabled = false)时,超链接将不会收到更改通知,例如即使绑定属性更改值,IsEnabledChanged 也不会被触发。

我的解决方案是更改我的 Xaml 以不再禁用祖先控件(这导致超链接的父控件被禁用)。由于父级 (TextBlock) 始终启用,现在超链接始终正确更新。

(我有点担心 IsEnabled 绑定的行为与 Controls 不同,而且我不确定如果我不能启用祖先,我会做什么......但这至少让我理解了我所遇到的问题拥有,让我解决它。)

详细信息:WPF 3.5 SP1

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

一身骄傲 2024-09-01 19:29:47

这不仅仅是超链接。它似乎更具体地说是 TextBlock,这当然是您用来在 WPF 中包装 HyperLink 的内容。这会产生同样的问题:

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

我希望设置 IsEnabled="True" 可以解决它,但似乎没有。

简单的解决方案是使用 StackPanelOrientation="Horizo​​ntal"

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文