开发者

Binding beyond the DataContext

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜