Why am I getting a “Cannot read property ‘nodeType’ of null” error with Knockout JS?

If you set up your code like this, it’ll work. <body> <p>Number1:<input data-bind=”value:n1″></p> <p>Number2:<input data-bind=”value:n2″></p> <p>Number3:<input data-bind=”value:n3″></p> <script src=”https://stackoverflow.com/questions/15090015/knockout.js”></script> <script> function ViewModel() { var self = this; self.n1 = ko.observable(10); self.n2 = ko.observable(10); self.n3 = ko.observable(10); } ko.applyBindings(new ViewModel()); ` </script> </body>

Pass command parameter to method in ViewModel in WPF?

“ViewModel” implies MVVM. If you’re doing MVVM you shouldn’t be passing views into your view models. Typically you do something like this in your XAML: <Button Content=”Edit” Command=”{Binding EditCommand}” CommandParameter=”{Binding ViewModelItem}” > And then this in your view model: private ViewModelItemType _ViewModelItem; public ViewModelItemType ViewModelItem { get { return this._ViewModelItem; } set { this._ViewModelItem = … Read more

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?.

Each Dictionary entry must have an associated key attribute

Note that Application.Resources requires an instance of ResourceDictionary, so you have to do something like this: <Application.Resources> <ResourceDictionary> <vm:ViewModelLocator x:Key=”Locator” xmlns:vm=”using:Scedule.ViewModel” /> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source=”Resource Dictionaries/StandardStyles.xaml”/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> So it’s not strange at all, it’s also not a bug. If you want your ResourceDictionary to be treated as a resource, you of course have … Read more

Binding ComboBox SelectedItem using MVVM

You seem to be unnecessarily setting properties on your ComboBox. You can remove the DisplayMemberPath and SelectedValuePath properties which have different uses. It might be an idea for you to take a look at the Difference between SelectedItem, SelectedValue and SelectedValuePath post here for an explanation of these properties. Try this: <ComboBox Name=”cbxSalesPeriods” ItemsSource=”{Binding SalesPeriods}” … Read more

MVVM: Should a VM object expose an M object directly, or only through getters delegating to M’s getters?

There is not a general agreement about that question. For example it was one of the open questions about MVVM formulated by Ward Bell here: Is the VM allowed to offer the V an unwrapped M-object (e.g., the raw Employee) ? Or must the M-object’s properties (if it is even permitted to have properties!) be … Read more

Binding [VisualStateManager] view state to a MVVM viewmodel?

Actually you can. The trick is to make an Attached property and add a property changed callback that actually calls GoToState: public class StateHelper { public static readonly DependencyProperty StateProperty = DependencyProperty.RegisterAttached( “State”, typeof( String ), typeof( StateHelper ), new UIPropertyMetadata( null, StateChanged ) ); internal static void StateChanged( DependencyObject target, DependencyPropertyChangedEventArgs args ) { … Read more

MVVM: Binding to Model while keeping Model in sync with a server version

In the past I ‘ve written an application that supports “live” editing of data objects from multiple locations: many instances of the app can edit the same object at the same time, and when someone pushes changes to the server everyone else gets notified and (in the simplest scenario) sees those changes immediately. Here’s a … Read more

WPF/MVVM – how to handle double-click on TreeViewItems in the ViewModel?

Updating my answer a bit. I’ve tried alot of different approaches for this and I still feel like Attached Behaviors is the best solution. Although it might look like alot of overhead in the begining it really isn’t. I keep all of my behaviors for ICommands in the same place and whenever I need support … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)