문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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?

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top