Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try using command bindings (you'll need <a href="http://msdn.microsoft.com/en-us/library/gg406140.aspx" rel="nofollow">prism</a>):</p> <pre><code>... &lt;ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"&gt; &lt;MenuItem Command="{Binding StartCommand}"/&gt; ... &lt;/ContextMenu&gt; ... </code></pre> <p>...</p> <pre><code>using Microsoft.Practices.Composite.Presentation.Commands; public class currentJob { public ICommand StartCommand {get; private set;} public currentJob () { StartCommand = new DelegateCommand(ExecuteStart, CanExecuteStart); } private bool CanExecuteStart() { //Determine whether start can be executed return true; } private void ExecuteStart() { //start here } } </code></pre> <p>Here, <code>ExecuteStart</code> replaces <code>startJob</code> and <code>CanExecuteStart</code> replaces <code>enablePermitted</code> in the original example.</p> <hr> <p><b>Edit</b> It probably helps to explain why your original code does not work. Changes to bound properties are only picked up if a "PropertyChange" event is fired by the property's object. Implementing <a href="http://msdn.microsoft.com/en-us/library/ms743695.aspx" rel="nofollow">INotifyPropertyChanged</a> would probably also fix your problem.</p> <hr> <p><b>Edit</b> An even more trivial problem with your original code is that it is binding to the wrong object - I presume no property startPermitted exists on FeedContextMenu (which anyway doesn't seem to be defined).</p> <hr> <p><b>Edit</b> There are still a few issues above: 1) the bindings are case-sensitive, so the binding should be {Binding StartCommand} etc. 2) You need to set the context menu on the individual items in the list. The following would work:</p> <pre><code> &lt;ListView Margin="10,10,10,55" Name="listviewCurrentJobs" ItemsSource="{Binding JobCollection}"&gt; &lt;ListView.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Border BorderBrush="Black" BorderThickness="2"&gt; &lt;StackPanel Orientation="Horizontal" MinHeight="20" Background="White"&gt; &lt;StackPanel.ContextMenu&gt; &lt;ContextMenu DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"&gt; &lt;MenuItem Header="Starten" Command="{Binding Path=StartCommand}"/&gt; &lt;MenuItem Header="Stoppen" Command="{Binding Path=StopCommand}"/&gt; &lt;MenuItem Header="Aktivieren" Command="{Binding Path=EnableCommand}"/&gt; &lt;MenuItem Header="Deaktivieren" Command="{Binding Path=DisableCommand}"/&gt; &lt;MenuItem Header="Löschen" Command="{Binding Path=DeleteCommand}"/&gt; &lt;/ContextMenu&gt; &lt;/StackPanel.ContextMenu&gt; &lt;Image Source="{Binding State}" Width="16"/&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/DataTemplate&gt; &lt;/ListView.ItemTemplate&gt; &lt;/ListView&gt; </code></pre>
    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.
 

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