开发者

Binding beyond the DataContext

开发者 https://www.devze.com 2023-03-25 15:07 出处:网络
I have a DataTemplate for templating my ItemsControl\'s items which are TimeSheet\'s Details. I havecouple of TextBox representing certain values of my TimeSheet\'s Details but their IsEnabled propert

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?


You can bind to your parent's DataContext:

{Binding DataContext.IsEnabled, 
         RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl}}
0

精彩评论

暂无评论...
验证码 换一张
取 消