TextBlock IsEnabled 绑定有什么问题?

发布于 2024-09-29 08:44:22 字数 631 浏览 0 评论 0原文

我有一个简单的文本块,其中包含标签和文本框作为内容。 我想将文本块的 IsEnabled 属性绑定到视图模型上的属性。无论出于何种原因,即使 IsEnabled 属性在视图模型上正确更改,标签和文本框仍保持禁用状态。

有人知道这是怎么回事吗?

这不起作用:

<TextBlock IsEnabled="{Binding Path=IsEnabledProperty}">
    <Label Content="Test"/>
    <TextBox Text="blah"/>
</TextBlock>

这工作得很好:

<TextBlock>
    <Label IsEnabled="{Binding Path=IsEnabledProperty}" Content="Test"/>
    <TextBox IsEnabled="{Binding Path=IsEnabledProperty}" Text="blah"/>
</TextBlock>

像这样使用 TextBlock 是一个坏主意吗?

I've got a simple text block with a label and text box as content.
I would like to bind the IsEnabled property of the text block to a property on my view model. For whatever reason the label and text box stay disabled even though the IsEnabled property is changing properly on the view model.

Anyone know what's going on here?

This doesn't work:

<TextBlock IsEnabled="{Binding Path=IsEnabledProperty}">
    <Label Content="Test"/>
    <TextBox Text="blah"/>
</TextBlock>

This works just fine:

<TextBlock>
    <Label IsEnabled="{Binding Path=IsEnabledProperty}" Content="Test"/>
    <TextBox IsEnabled="{Binding Path=IsEnabledProperty}" Text="blah"/>
</TextBlock>

Is it just a bad idea to use TextBlock like this?

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

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

发布评论

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

评论(3

我不吻晚风 2024-10-06 08:44:22

是的,这是一个坏主意。当您将非字符串对象放置在 Text 属性中时,它将用作内容元素,就像在 FlowDocument 中一样,因此不像普通 FrameworkElements 那样具有交互性。

Yes, it's a bad idea. When you place non-string objects in the Text property it is used as content elements, like in a FlowDocument, and therefore isn't interactive like normal FrameworkElements.

我三岁 2024-10-06 08:44:22

您尝试过 StackPanel 吗?

   <StackPanel Orientation="Horizontal" IsEnabled="{Binding Path=IsEnabledProperty}">
    <Label Content="Test"/>
    <TextBox Text="blah"/>
   </StackPanel>

您的 IsEnabledProperty 是依赖属性吗?

Have you tried a StackPanel instead?

   <StackPanel Orientation="Horizontal" IsEnabled="{Binding Path=IsEnabledProperty}">
    <Label Content="Test"/>
    <TextBox Text="blah"/>
   </StackPanel>

Is your IsEnabledProperty a dependency property?

德意的啸 2024-10-06 08:44:22

您确定在 viewModel 中更新属性 IsEnableProperty 时引发 PropertyChanged 事件吗?

Are you sure that your raises the PropertyChanged event for your property IsEnableProperty when you update it in the viewModel ?

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