Note that there are some explanatory texts on larger screens.

plurals
  1. POWP7: Binding to an element outside pivot.itemtemplate
    primarykey
    data
    text
    <p>I've been struggling for a while on this. I'm a bit of a newbie, but i lurked a lot and still couldn't find a solution to my problem, so I decided to post my question here.</p> <p>I'm binding a pivot to a collection of objects I want to display to create a gallery. Here is my pivot control bound to a list called gallery, where each object contains 2 strings (url and description).</p> <pre><code>&lt;controls:Pivot ItemsSource="{Binding gallery}" Grid.Row="0" x:Name="galleryPivot"&gt; &lt;controls:Pivot.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Image Source="{Binding url}" /&gt; &lt;Grid Visibility="{Binding ElementName=galleryPivot, Path=DataContext.ShowDetail}"&gt; &lt;ListBox&gt; &lt;ListBoxItem&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding description}" /&gt; &lt;/StackPanel&gt; &lt;/ListBoxItem&gt; &lt;/ListBox&gt; &lt;/Grid&gt; &lt;/Grid&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/controls:Pivot.ItemTemplate&gt; &lt;/controls:Pivot&gt; </code></pre> <p>The datacontext is the viewmodel and initialized in the constructor of the page. Here is my ViewModel:</p> <pre><code>public class GalleryViewModel : INotifyPropertyChanged { public List&lt;Gallery&gt; gallery { get { return Globals.pictures; } } private Visibility _showDetail = Visibility.Collapsed; public Visibility ShowDetail { get { return _showDetail; } set { _showDetail = value; RaisePropertyChanged("ShowDetail"); } } public GalleryViewModel() { } public event PropertyChangedEventHandler PropertyChanged = delegate { return; }; protected void RaisePropertyChanged(string propertyName) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } </code></pre> <p>The gallery object is a list in my ViewModel, as the ShowDetail property. As ShowDetail is outside the scope, I tried to set ElementName as explained <a href="https://stackoverflow.com/questions/4640370/wp7-why-does-a-listbox-itemspanel-break-my-elementname-data-binding">here.</a></p> <p>The pivot binds well to the gallery list, but when I change the value of ShowDetail, the grid won't hide. I also tried to set ElementName to LayoutRoot but it still won't work.</p> <p>My question, how can I bind the visibility when it is outside the scope of the itemtemplate?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload