Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't want to reference UI elements by name in the code-behind. Actually any time you can avoid naming an object you <a href="https://stackoverflow.com/questions/3100007/not-specifying-control-names-in-wpf-performance-effect">save a little in performance</a>. And by setting up your app to use MVVM properly, you gain in performance, readability, maintainability, and code separation.</p> <p>You want to abstract things further to use the MVVM pattern. You're doing your bindings correctly but consider the pattern. Your view is all correct. Consider adding a class that holds the properties defined currently in your code-behind and the methods called in your event handlers.</p> <pre><code>public class ViewModel : INotifyPropertyChanged { private FunctionalTester _funcTester; public FunctionalTester FuncTester { get { return _funcTester; } set { _funcTester = value; OnPropertyChanged( "FuncTester" ); } } public async void TestAsync( ) { await _funcTester.Test( ); } } </code></pre> <p>A binding to the FuncTester would simply be <code>SomeProperty="{Binding FuncTester}"</code> because the object is set as the DataContext of your view. A decent article that expands on this idea <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow noreferrer">is found here</a>.</p> <p>Obviously left out some things (like <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx" rel="nofollow noreferrer">INotifyPropertyChanged</a> implementation and other properties you've defined) for brevity. But just make this class and assign it as your view model. Then the UI (the Xaml and the code-behind) only really deal with the UI and the ViewModel really deals with the data and logic. Great separation. For your event handler, just call <code>((ViewModel)this.DataContext).Test( );</code> and you can plug-and-play your ViewModel's to change functionality on the fly. Hope this helps!</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. 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