Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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 ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top