0

I have a DataTemplate for templating my ItemsControl's items which are TimeSheet's Details. I have couple of TextBox representing certain values of my TimeSheet's Details but their IsEnabled property depends on the TimeSheet itself, not the details.

<ItemsControl ItemsSource="{Binding Path=TimeSheet.TimeSheetDetails}" ItemTemplate="{StaticResource TimeSheetDetail}" /> <DataTemplate x:Key="TimeSheetDetail"> <TextBox Text="{Binding Houre}" IsEnabled="Binding ??????"> </DataTemplate> 

Since the IsEnabled property cant be found in the TimeSheetDetails but can be found in my ViewModel, i would like to bind directly to my ViewModel's Property but when i try binding, to my ViewModel from my DataTemplate, it only seems to look in my TimeSheetDetail.

How can i access my ViewModel's public property directly?

1

1 Answer 1

2

You can bind to your parent's DataContext:

{Binding DataContext.IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl}} 
Sign up to request clarification or add additional context in comments.

1 Comment

Ty alot, really usefull but you made a small mistake, its more like IsEnabled="{Binding DataContext.IsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl}}" because TimeSheet alredy is the DataContext.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.