icommand

binding a command inside a listbox item to a property on the viewmodel parent

你说的曾经没有我的故事 提交于 2019-12-08 23:18:02
问题 I've been working on this for about an hour and looked at all related SO questions. My problem is very simple: I have HomePageVieModel: HomePageVieModel +IList<NewsItem> AllNewsItems +ICommand OpenNews My markup: <Window DataContext="{Binding HomePageViewModel../> <ListBox ItemsSource="{Binding Path=AllNewsItems}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock> <Hyperlink Command="{Binding Path=OpenNews}"> <TextBlock Text="{Binding Path=NewsContent}" /> </Hyperlink> <

After installing .NET 4.5, previous Unit-Test project fails to build

不打扰是莪最后的温柔 提交于 2019-12-08 14:36:08
问题 I have a .NET 4.0 WPF solution that includes a Unit Test project which tests the different commands used in the viewmodels. Everything was fine. Then I installed .NET framework 4.5 and then VS2012, and started getting error messages like - XYZProject.UsersViewModel_Accessor.AddUserToAccountsCommand' is not supported by the language Before installing VS2012 the UnitTestFramework.dll was referenced from - C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\ which was

Is it safe to call new RelayCommand (ICommand) in Expression-Bodied Properties

寵の児 提交于 2019-12-08 01:24:20
问题 With expression bodied properties we can create a RelayCommand as follows public RelayCommand Command => _command ?? (_command = new RelayCommand(CommandExecute)); However this is possible also public RelayCommand Command => new RelayCommand(CommandExecute); Obviously this creates a new RelayCommand every time the Property getter is called. Though there is comments i have seen around that says the underlying plumbing only creates one command... Does anyone have a definitive answer on this?

Adding MouseBindings to Items in a databound WPF ListView

亡梦爱人 提交于 2019-12-07 15:55:17
问题 I'm trying to get a command in my ViewModel executed when the user clicks on a item in a ListView. When I add a ListViewItem in XAML I can just add a MouseBinding to its InputBindings . <ListView> <ListView.View> <GridView> <GridViewColumn Header="Test" /> </GridView> </ListView.View> <ListViewItem Content="Item 1" > <ListViewItem.InputBindings> <MouseBinding Gesture="LeftDoubleClick" Command="{Binding DoubleClickCommand}" /> </ListViewItem.InputBindings> </ListViewItem> </ListView> But how

Should I check an ICommand's CanExecute method before calling Execute from procedural code?

ⅰ亾dé卋堺 提交于 2019-12-06 23:04:32
问题 When using ICommand s in XAML, WPF uses the CanExecute method to enable or disable controls associated with the command. But what if I am calling Execute from procedural code? Should I first check CanExecute to make sure that the command can execute, or should Execute take care of this check for me? In other words, should I do this: if (someCommand.CanExecute(parameter, target)) someCommand.Execute(parameter, target); Or just this: someCommand.Execute(parameter, target); 回答1: Good style would

Silverlight MVVM: where did my (object sender, RoutedEventArgs e) go?

[亡魂溺海] 提交于 2019-12-06 06:12:31
I am using commanding in my viewmodel to handle events. like for example I am handling a button click event like this: XAML <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <i:InvokeCommandAction Command="{Binding mvvmButtonclick}" /> </i:EventTrigger> </i:Interaction.Triggers> Viewmodel Code public ICommand mvvmButtonclick { get; private set; } Viewmodel Constructor code to wireup the command this.mvvmButtonclick = new ActionCommand(this.ButtonClickedEvent); Actual method in the viewmodel that gets called on button click private void ButtonClickedEvent() { MessageBox.Show("worked!!

Button Command CanExecute not called when property changed

随声附和 提交于 2019-12-06 02:46:25
问题 I have a form with a textbox and a button. When that textbox has it's value changed, the button command doesn't call the CanExecute method of it's command. The command parameter is set but doesn't seem to change. After load the window, the button remains disabled. <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /> <Button Content="Save" Command="{Binding SaveChangesCommand}" CommandParameter="{Binding Name}" /> I know the binding is working because I created a

Saving a WPF canvas as an image following MVVM Pattern

折月煮酒 提交于 2019-12-06 01:45:44
问题 I have a canvas, e.g. similar to this solution or many others using the ItemsControl . Now I want a button which should be bound to an ICommand. This command should call a method of ViewModel class which can save the image. The saving method is clear, but how do I do the binding following the MVVM pattern? 回答1: You could pass the Canvas to the ViewModel's Save method using a CommandParameter <Button Content="Save" Command="{Binding SaveCanvasCommand}" CommandParameter="{Binding ElenementName

Adding MouseBindings to Items in a databound WPF ListView

大城市里の小女人 提交于 2019-12-05 20:48:47
I'm trying to get a command in my ViewModel executed when the user clicks on a item in a ListView. When I add a ListViewItem in XAML I can just add a MouseBinding to its InputBindings . <ListView> <ListView.View> <GridView> <GridViewColumn Header="Test" /> </GridView> </ListView.View> <ListViewItem Content="Item 1" > <ListViewItem.InputBindings> <MouseBinding Gesture="LeftDoubleClick" Command="{Binding DoubleClickCommand}" /> </ListViewItem.InputBindings> </ListViewItem> </ListView> But how can this be achived in a databound ListView? <ListView ItemsSource="{Binding Patients}"> <ListView.View>

Should I check an ICommand's CanExecute method before calling Execute from procedural code?

血红的双手。 提交于 2019-12-05 03:09:35
When using ICommand s in XAML, WPF uses the CanExecute method to enable or disable controls associated with the command. But what if I am calling Execute from procedural code? Should I first check CanExecute to make sure that the command can execute, or should Execute take care of this check for me? In other words, should I do this: if (someCommand.CanExecute(parameter, target)) someCommand.Execute(parameter, target); Or just this: someCommand.Execute(parameter, target); Good style would dictate that you should do the former, check CanExecute first. This will enforce proper decomposition and a