Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It doesn't work because you have tried to <code>Bind</code> the <code>Command</code> to the <code>ItemsControl</code> and not the <code>Button</code> controls. Have you tried this?:</p> <pre><code>&lt;DataTemplate&gt; &lt;Button Content="{Binding}" Command="{Binding DataContext.ZoomToAddressCommand, RelativeSource={RelativeSource AncestorType={x:Type YourViewNamespace:YourViewName}}}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>What we're attempting to do here is to <code>Bind</code> from the <code>DataTemplate</code> to the view model that I am assuming is set as the <code>DataContext</code> of the current view. Please replace "<code>YourViewNamespace:YourViewName</code>" with the actual names of your XML namespace and view.</p> <p>UPDATE >>></p> <p>Ok, after looking at your code again, I can see that you are <code>Binding</code> to the <code>Addresses</code> collection simply using the property name. You say that the <code>DataContext</code> is set on the <code>ItemsControl</code>, so I'm assuming that by that you mean that your view model is set on the <code>ItemsControl.DataContext</code> property. If that is so, then we need to change our <code>Binding</code> to the <code>Command</code> like this:</p> <pre><code>&lt;DataTemplate&gt; &lt;Button Content="{Binding}" Command="{Binding DataContext.ZoomToAddressCommand, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>If your view model is not set on the <code>ItemsControl.DataContext</code> property, then this will not work and you will need to clearly tell me how you have connected your view model to your view. Before I just assumed that your view model was data bound to the <code>DataContext</code> of the containing view or <code>Window</code> as is normally done... maybe next time, you can provide this information in your question to make it easier for people to answer it?</p> <p>UPDATE 2 >>></p> <p>Ok, you've updated the question with the essential <code>DataContext</code> information... perfect. Now I can answer your question properly without all the guessing... do you see how much easier this would have been if you had added that there in the first place? No matter... we're here now. Try this final example:</p> <pre><code>&lt;DataTemplate&gt; &lt;Button Content="{Binding}" Command="{Binding DataContext.ZoomToAddressCommand, RelativeSource={RelativeSource AncestorType={x:Type TabItem}}}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>To reiterate... this <code>RelativeSource Binding</code> will look up the visual tree until it finds a <code>TabItem</code> control. Then, it will look at the <code>DataContext</code> property of that control. Finally, it will look for a <code>ZoomToAddressCommand</code> property in the object (your view model) that is set as the <code>DataContext</code> of the <code>TabItem</code>... and there we are.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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