Note that there are some explanatory texts on larger screens.

plurals
  1. POBind button click to method on underlying datasource
    primarykey
    data
    text
    <p>I am trying to bind a button click event in a bound ListView to a method on the list's underlying data source. I've searched for this but all of the examples seem to list pages of code and I'm pretty sure this can be achieved with a binding expression - or at least I hope so!</p> <p>The underlying data source is a collection of this class...</p> <pre><code>public class AppTest : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; int _priority; string _testName; public void RunTest() { // TODO: Implement } public int Priority { get { return _priority; } set { _priority = value; NotifyPropertyChanged("Priority"); } } public string TestName { get { return _testName; } set { _testName = value; NotifyPropertyChanged("TestName"); } } protected void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } </code></pre> <p>... and the XAML looks like this ...</p> <pre><code>&lt;Window.Resources&gt; &lt;CollectionViewSource x:Key="cvs" x:Name="cvs" Source=""&gt; &lt;CollectionViewSource.SortDescriptions&gt; &lt;scm:SortDescription PropertyName="Priority" Direction="Ascending" /&gt; &lt;/CollectionViewSource.SortDescriptions&gt; &lt;/CollectionViewSource&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;ListView x:Name="TestList" ItemsSource="{Binding Source={StaticResource cvs}}"&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;Application:AppTestControl Message="{Binding TestName}" /&gt; &lt;Button x:Name="btnRunTest"&gt; Run Test &lt;/Button&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListView&gt; &lt;/Grid&gt; </code></pre> <p>How can I bind the click of <code>btnRunTest</code> to the <code>RunTest()</code> method in the bound underlying object?</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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