Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF access parent ViewModel from inside a ContentTemplate
    primarykey
    data
    text
    <p>I have a TabControl with templated content as below:</p> <pre><code>&lt;TabControl x:Name="Items" SelectedItem="{Binding ActiveItem}" TabStripPlacement="Left" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"&gt; &lt;TabControl.ItemContainerStyle&gt; &lt;!--Some style stuff--&gt; &lt;/TabControl.ItemContainerStyle&gt; &lt;TabControl.Template&gt; &lt;ControlTemplate TargetType="{x:Type TabControl}"&gt; &lt;!--Some structure stuff including a tabpanel and contentPresenter--&gt; &lt;/ControlTemplate&gt; &lt;/TabControl.Template&gt; &lt;TabControl.ContentTemplate&gt; &lt;DataTemplate&gt; &lt;Button x:Name="MyButton" Visibility="{Binding x}" /&gt; &lt;/DataTemplate&gt; &lt;/TabControl.ContentTemplate&gt; &lt;/TabControl&gt; </code></pre> <p>The view containing this TabControl uses a ViewModel similar to this:</p> <pre><code>public class MyPageViewModel : ScreenConductorViewModelBase&lt;IMyTab&gt; { public Visibility x = Visibility.Hidden; } </code></pre> <p>I would like the visibility of the button inside the template to pull from my parent(?) ViewModel, however its trying to retrieve x from the items viewModel. </p> <p>This makes sense to me but Im not sure how to specify that this field should come from the parent instead.</p> <p>I've tried a few things but none of them seem to work:</p> <pre><code> {Binding x} {Binding DataContext.x} {Binding RelativeSource={RelativeSource TemplatedParent}, Path=x} </code></pre> <p>Im sure it must be simple to do this but I cant seem to work out the binding syntax</p>
    singulars
    1. This table or related slice is empty.
    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.
    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