How can I tell my DataTemplate to bind to a property in the PARENT ViewModel?

The answer is this: <DataTemplate x:Key=”CodeGenerationMenuTemplate”> <MenuItem Header=”{Binding Title}” Command=”{Binding DataContext.SwitchPageCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Menu}}}” CommandParameter=”{Binding Title}”/> </DataTemplate> I just saw that Nir had given me the syntax to solve the above issue on this question: What is the best way in MVVM to build a menu that displays various pages?.

MVVM for winforms [duplicate]

I think that there are two answers here… really just one answer to “Should I” and one answer to “Could I”. As far as “Could I”, it is certainly possible. MVVM really just relies on a view that can bind to a view model. Since WinForms supports binding, this certainly is possible. You may need … Read more

What to use? MVC, MVP or MVVM or…?

Actually, the ultimate post you’re looking for is this answer this answer from Karsten Lentzsch (of JGoodies fame) in the Swing Frameworks and Best Practices Swing Frameworks and Best Practices thread. Hello, I’ve been writing Swing apps for several years that many people find elegant. And I teach developers in working with Swing efficiently: how … Read more

Moving to next control on Enter keypress in WPF

Below is an attached property that I’ve used for just this. First, example usage: <TextBox Width=”100″ Text=”{Binding Name, Mode=TwoWay}” UI:FocusAdvancement.AdvancesByEnterKey=”True” /> (UI is the namespace alias for where I’ve defined the following.) The attached property: public static class FocusAdvancement { public static bool GetAdvancesByEnterKey(DependencyObject obj) { return (bool)obj.GetValue(AdvancesByEnterKeyProperty); } public static void SetAdvancesByEnterKey(DependencyObject obj, bool … Read more

How can I sort a ListBox using only XAML and no code-behind?

Use a CollectionViewSource: <CollectionViewSource x:Key=”SortedItems” Source=”{Binding CollectionOfStrings}” xmlns:scm=”clr-namespace:System.ComponentModel;assembly=Win‌​dowsBase”> <CollectionViewSource.SortDescriptions> <scm:SortDescription PropertyName=”SomePropertyOnYourItems”/> </CollectionViewSource.SortDescriptions> </CollectionViewSource> <ListBox ItemsSource=”{Binding Source={StaticResource SortedItems}}”/> You might want to wrap your strings in a custom VM class so you can more easily apply sorting behavior.

Setting application wide HTTP headers in AngularJS

You can use default headers for angular 1.0.x: $http.defaults.headers.common[‘Authentication’] = ‘authentication’; or request interceptor for angular 1.1.x+: myapp.factory(‘httpRequestInterceptor’, function () { return { request: function (config) { // use this to destroying other existing headers config.headers = {‘Authentication’:’authentication’} // use this to prevent destroying other existing headers // config.headers[‘Authorization’] = ‘authentication’; return config; } }; … Read more

Android ViewModel has no zero argument constructor

In my case as I’m using HILT, it was lacking one annotation above the Fragment that has a ViewModel: @AndroidEntryPoint @AndroidEntryPoint class BestFragment : Fragment() { …. Of course in your ViewModel class you also need to Annotate with what HILT needs: @ViewModelInject class BestFragmentViewModel @ViewModelInject constructor(var userManager: UserManager) : ViewModel() { …. }

Prism Custom Confirmation Interaction

Main thing is, when you raise the interaction, provide a callback that is triggered when the interaction is finished. This callback gets the notification back and your interaction should have stored all potentially interesting return values there. Here’s an example… Relevant parts of the ViewModel: public InteractionRequest<SelectQuantityNotification> SelectQuantityRequest { get; } // in some handler … Read more

tech