commandbinding

WPF Routed Command with Bindings per-Tab

拜拜、爱过 提交于 2019-12-01 10:09:27
问题 I intended to disable and enable the Buttons outside the TabControl, just like those inside the TabItem when the current tab is changed. But the CommandBindings of the TabItem do not seem to impact "up" the visual tree. What is the right way to do this? With this XAML: <Window x:Class="WpfApplication10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication10" Title=

Using the parent's DataContext (WPF - Dynamic Menu Command Binding)

放肆的年华 提交于 2019-11-30 12:36:37
问题 I looked over this web and google and the solutions didn't work for me. I have a command on the ViewModel of a UserControl. Well, The usercontrol have a ItemsControl binded to a ObservableCollection. Inside the DataTemplate of the ItemsControl.ItemTemplate I have a button and I want to use the command. I can't bind the command because inside the DataTemplate, the datacontext is not the ViewModel but an item of the ObservableCollection. The question is: How can I bind the button to the command

MVVM View event Viewmodel command binding

回眸只為那壹抹淺笑 提交于 2019-11-30 09:37:40
问题 I'm looking for a good (read: simple) example on how to implement event aggregators with Prism. I've never used Prism and I'm also quite new to MVVM itself. I have a WPF canvas as a View and I want to handle the MouseUp event on the canvas in the Viewmodel. Now the powers that be at our organization wants me to use Prism, and apparently Prism recommends using event aggregators, which is why I need a sample to get me started. 回答1: all you need for this is the EventToCommand behavior from

Using the parent's DataContext (WPF - Dynamic Menu Command Binding)

我是研究僧i 提交于 2019-11-30 02:54:16
I looked over this web and google and the solutions didn't work for me. I have a command on the ViewModel of a UserControl. Well, The usercontrol have a ItemsControl binded to a ObservableCollection. Inside the DataTemplate of the ItemsControl.ItemTemplate I have a button and I want to use the command. I can't bind the command because inside the DataTemplate, the datacontext is not the ViewModel but an item of the ObservableCollection. The question is: How can I bind the button to the command if a lost the parent datacontext? I think that this need to have an easy solution because I think that

UI action in middle of MvxCommand

ぃ、小莉子 提交于 2019-11-29 08:00:41
I am using MvvmCross, but this may be general command binding. When user click a button, the application require an extra input data before proceed to what I want to do in the actual command. The problem that I cannot call an UI action in middle of ViewModel, so just binding MvxCommand (or any ICommand) would not work. One may ask why: 1) I don't put an input on the UI and user can enter data before click button -> I don't have space. 2) Make default data, and let user change it later -> This my first though, but user tend to forget to change it later!! So can someone come up with a solution?

Bind command to Loaded event of view

点点圈 提交于 2019-11-29 01:38:56
问题 I am trying to get a method to run when a view has finished loading. I have tried to bind a command to the Loaded event in the view but it fails to run. The inner exception that is thrown is 'Provide value on 'System.Windows.Data.Binding' threw an exception.' Line number '14' and line position '14' <UserControl x:Class="Components.Map.MapView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:map="clr-namespace

How to Bind a Command in WPF

不问归期 提交于 2019-11-28 23:31:01
Sometimes we used complex ways so many times, we forgot the simplest ways to do the task. I know how to do command binding, but i always use same approach. Create a class that implements ICommand interface and from the view model i create new instance of that class and binding works like a charm. This is the code that i used for command binding public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; testCommand = new MeCommand(processor); } ICommand testCommand; public ICommand test { get { return testCommand; } } public void processor() {

Application Level shortcut keys in WPF

那年仲夏 提交于 2019-11-28 12:23:47
In WPF application I am currently trying to bind a Command to launch a calculator Tool form any where in the application using shortcut keys, I have created a command but not getting how to map commands and shortcut keys to create universal shortcut keys in my application. Thanks in advance. Grokys You can do this in xaml - see the example in the documentation for the KeyBinding class: <Window.InputBindings> <KeyBinding Command="ApplicationCommands.Open" Gesture="CTRL+R" /> </Window.InputBindings> Update: Looks like you can't actually bind a KeyBinding to a ViewModel using just xaml if you're

UI action in middle of MvxCommand

▼魔方 西西 提交于 2019-11-28 01:23:58
问题 I am using MvvmCross, but this may be general command binding. When user click a button, the application require an extra input data before proceed to what I want to do in the actual command. The problem that I cannot call an UI action in middle of ViewModel, so just binding MvxCommand (or any ICommand) would not work. One may ask why: 1) I don't put an input on the UI and user can enter data before click button -> I don't have space. 2) Make default data, and let user change it later -> This

How to Bind a Command in WPF

梦想的初衷 提交于 2019-11-27 21:15:57
问题 Sometimes we used complex ways so many times, we forgot the simplest ways to do the task. I know how to do command binding, but i always use same approach. Create a class that implements ICommand interface and from the view model i create new instance of that class and binding works like a charm. This is the code that i used for command binding public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; testCommand = new MeCommand(processor); }