TextBlock IsEnabled 绑定有什么问题?
我有一个简单的文本块,其中包含标签和文本框作为内容。 我想将文本块的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是一个坏主意。当您将非字符串对象放置在 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.
您尝试过 StackPanel 吗?
您的 IsEnabledProperty 是依赖属性吗?
Have you tried a StackPanel instead?
Is your IsEnabledProperty a dependency property?
您确定在 viewModel 中更新属性 IsEnableProperty 时引发 PropertyChanged 事件吗?
Are you sure that your raises the PropertyChanged event for your property IsEnableProperty when you update it in the viewModel ?