icommand

ICommand.CanExecute being passed null even though CommandParameter is set...

I have a tricky problem where I am binding a ContextMenu to a set of ICommand-derived objects, and setting the Command and CommandParameter properties on each MenuItem via a style: <ContextMenu ItemsSource="{Binding Source={x:Static OrangeNote:Note.MultiCommands}}"> <ContextMenu.Resources> <Style TargetType="...

How to bind the Command property of the ItemTemplate CheckBox to ViewModel object's property?

Let me ask this question with a pseudo code: <Window> <ListView ItemsSource="{Binding PersonCollection}"> <ListView.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock Text="{Binding Path=Name}" /> <TextBlock Text="{Binding Path=Age}" /> ...

WPF CommandBinding NOT on the top level item/Window/this

All I wanted was different bindings on different tabs, so switching tabs would toggle command availability. I thought CommandBindings worked that way. But I've spent the last while trying to get this simple sample to work. Either I fundamentally misunderstand (and that would not be a first) or something's wrong. I add a CommandBinding...

CommandConverter - Valid exception or .NET Bug

I'm getting an exception in my C#/.NET application that reads: 'CommandCoverter' is unable to convert 'MyNamespace.MyDerivedFromICommandSubclass' to 'System.String'. What I'm doing is fairly straight forward, as described by the MSDN ICommand documentation: public class MyDerivedFromICommandSubclass : ICommand { // Implement int...

MVVM with UI specific events on codebehind

I have a Silverlight page that has few controls and all of the behaviors are not databound. For example, RichTextBox is databound for the Text property. But the controls behaviors like Bold, Italic, Numbered, etc are driven from a button click event from toolbar above the control. These controls do change the value of the Data, but do no...

Test if ICommand was executed

Hi, My questions is the following: how can I test if an ICommand's Execute method was called on a mock object ? I'm using the following code: var mockOperandVM = new Mock<UCOperandViewModel> (); mockOperandVM.Setup (x => x.EditCommand).Returns (new RelayCommand<String> (x => { })); var toolbarTrayVM = new UCToolbarTrayViewModel (...

How to set EventArg for ICommand?

in VM, set ICommand like: private RelayCommand<EventArgs> _myCommand = null; public RelayCommand<EventArgs> MyCommand { get { if (_myCommand == null) { _myCommand = new RelayCommand<EventArgs>((e) => { //.... } ...

What is the real advantage of keeping code out of the XAML code behind?

There is a lot of effort in the Silverlight community to keep a XAML's code behind file as free of code as possible. What is the real motivation behind this? For example, what is the advantage of using a command instead of an event handler? If I have <Button x:Name="SaveButton" Content="Save" Click="SaveButton_Click" /> ... private...

MVC (not mvvm) for WPF ?

I do not like having Controller-related code (understand ICommand stuff) in my ViewModel in WPF. Is there a framework to separate it and getting back to good old MVC for WPF? I would like to get : - a view in XAML - a view model - a model - command handlers ...

WPF Custom ICommand implementation and the CanExecuteChanged event

Hi, in my WPF UI, I use RoutedCommands that I refer to in my xaml via the following code: Command="viewModel:MessageListViewModel.DeleteMessagesCommand" I don't like this static link to my ViewModel class,I think this is not as nice as creating a custom ICommand implementation and use a syntax like the following Command="{Binding De...

C#/WPF: KeyBinding not triggering Command

I have declared <InputBindings> <UserControl.InputBindings> <KeyBinding Key="C" Modifiers="Ctrl" Command="{Binding CopyImageCommand}" /> <KeyBinding Key="V" Modifiers="Ctrl" Command="{Binding PasteImageCommand}" /> </UserControl.InputBindings> For testing purposes, I have added buttons bound to those commands too <Button Comm...

ViewModel in Class project

I'm building a WPF application which is based on the MVVM pattern. Later on we are going to build a Silverlight application of the same type, and also a Web application. I want to use my ViewModels in all three UI:s, so my idea was to move the vm:s to a class library, but then I lost my ICommands, is there an easy way to get around t...