Wpf 什么';TextBlock IsEnabled绑定有什么问题?
我有一个简单的文本块,带有标签和文本框作为内容。 我想将文本块的IsEnabled属性绑定到视图模型上的属性。无论出于何种原因,标签和文本框保持禁用状态,即使视图模型上的IsEnabled属性正在正确更改 有人知道这是怎么回事吗 这不起作用:Wpf 什么';TextBlock IsEnabled绑定有什么问题?,wpf,data-binding,textblock,isenabled,Wpf,Data Binding,Textblock,Isenabled,我有一个简单的文本块,带有标签和文本框作为内容。 我想将文本块的IsEnabled属性绑定到视图模型上的属性。无论出于何种原因,标签和文本框保持禁用状态,即使视图模型上的IsEnabled属性正在正确更改 有人知道这是怎么回事吗 这不起作用: <TextBlock IsEnabled="{Binding Path=IsEnabledProperty}"> <Label Content="Test"/> <TextBox Text="blah"/>
<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 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是个坏主意吗 您尝试过StackPanel吗
<StackPanel Orientation="Horizontal" IsEnabled="{Binding Path=IsEnabledProperty}">
<Label Content="Test"/>
<TextBox Text="blah"/>
</StackPanel>
您的IsEnabled属性是依赖项属性吗?您是否尝试过使用StackPanel
<StackPanel Orientation="Horizontal" IsEnabled="{Binding Path=IsEnabledProperty}">
<Label Content="Test"/>
<TextBox Text="blah"/>
</StackPanel>
您的IsEnabled属性是依赖项属性吗?是的,这不是个好主意。在文本属性中放置非字符串对象时,它被用作内容元素,就像在FlowDocument中一样,因此不像普通的框架元素那样具有交互性。是的,这不是一个好主意。在文本属性中放置非字符串对象时,它将用作内容元素,如在FlowDocument中,因此,它不像普通的框架元素那样具有交互性。在viewModel中更新属性时,是否确实引发属性的PropertyChanged事件为EnableProperty?在viewModel中更新属性时,是否确实引发属性的PropertyChanged事件为EnableProperty?是的。堆栈面板是正确的选择。我不知道我在哪里看到TextBlock最初是这样使用的!?是时候改掉坏习惯了。堆栈面板是正确的选择。我不知道我在哪里看到TextBlock最初是这样使用的!?是时候改掉坏习惯了。