Access property of DataContext in ItemTemplate
Posted
by
amrinder
on Stack Overflow
See other posts from Stack Overflow
or by amrinder
Published on 2011-01-03T00:26:05Z
Indexed on
2011/01/05
8:53 UTC
Read the original article
Hit count: 229
xaml
|windows-phone-7
My datacontext has two properties: Items which is a collection and DetailsVisiblity
which is enum of type Visiblity
.
On the page I have a Listbox
with ItemsSource="{Binding Entries}"
. Inside the DataTemplate
, I can bind stuff to properties of Items, but how do I get access to DetailsVisiblity
which is a property of DataContext
?
DataContext
has two properties: ObservableCollection<Item> Entries
, and Visibility DetailsVisiblity
. Item class has two properties: Title and Details.
Here is the view. How do I bind Visiblity
of the second TextBlock
to DetailsVisiblity
property?
<ListBox "{Binding Items}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Title}" />
<TextBlock Text="{Binding Details}" Visibility="{Binding ???}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
© Stack Overflow or respective owner