commandparameter

How do I pass the Button as CommandParameter from XAML in a Xamarin.Forms Page?

◇◆丶佛笑我妖孽 提交于 2019-11-30 17:36:21
I would like to pass a Xamarin.Forms.Button in it's own Command as the CommandParameter to my ViewModel. I know how to achieve this from the code behind e.g. ... XAML (with most properties missed out for brevity) <Button x:Name="myButton" Text="My Button" Command="{Binding ButtonClickCommand}"/> XAML.cs public partial class MyTestPage { public MyTestPage() { InitializeComponent(); myButton.CommandParameter = myButton; } } ViewModel public class MyViewModel : ViewModelBase { public MyViewModel() { ButtonClickCommand = new Command( (parameter) => { var view = parameter as Xamarin.Forms.Button;

passing the current Window as a CommandParameter

痴心易碎 提交于 2019-11-30 13:10:03
问题 how can I pass the window I am currently on as a parameter to a command? I like to do this in XAML-markup: <Button Command="CommandGetsCalled" CommandParameter="-this?-" /> 回答1: There are two ways I can of think to do this: Give the window a name (via a x:Name attribute on the Window tag, and then construct a binding like this (assumes the name of the window is 'ThisWindow'): <Button Command="CommandGetsCalled" CommandParameter="{Binding ElementName=ThisWindow}" /> For something more general

WPF: Menu Items only bind command parameters once

南楼画角 提交于 2019-11-30 08:52:24
问题 Ive noticed this a couple of times when using menus with commands, they are not very dynamic, check this out. I am creating a menu from a collection of colours, I use it to colour a column in a datagrid. Anyway when i first bring up the menu (its a context menu) the command parameter binding happens and it binds to the column that the context menu was opened on. However the next time i bring it up it seems wpf caches the menu and it doesnt rebind the command parameter. so i can set the colour

How do I pass the Button as CommandParameter from XAML in a Xamarin.Forms Page?

☆樱花仙子☆ 提交于 2019-11-30 01:27:27
问题 I would like to pass a Xamarin.Forms.Button in it's own Command as the CommandParameter to my ViewModel. I know how to achieve this from the code behind e.g. ... XAML (with most properties missed out for brevity) <Button x:Name="myButton" Text="My Button" Command="{Binding ButtonClickCommand}"/> XAML.cs public partial class MyTestPage { public MyTestPage() { InitializeComponent(); myButton.CommandParameter = myButton; } } ViewModel public class MyViewModel : ViewModelBase { public MyViewModel

How to correctly bind menu items?

时光怂恿深爱的人放手 提交于 2019-11-29 19:30:26
问题 How do i correctly bind a dynamical created list of menu items. I have tried several thing but none seem to work. I get the proper list of names, however my ViewSwitchCommand does not seem to fire correctly. <MenuItem Foreground="White" Header="Names" ItemsSource="{Binding Player.ToonNames}" Command="{Binding ViewSwitchCommand}" CommandParameter="{Binding Header}"/> However if i don't do it dynamically and do it like this then everything works just fine can get it to work <MenuItem Foreground

WPF: Menu Items only bind command parameters once

戏子无情 提交于 2019-11-29 08:24:55
Ive noticed this a couple of times when using menus with commands, they are not very dynamic, check this out. I am creating a menu from a collection of colours, I use it to colour a column in a datagrid. Anyway when i first bring up the menu (its a context menu) the command parameter binding happens and it binds to the column that the context menu was opened on. However the next time i bring it up it seems wpf caches the menu and it doesnt rebind the command parameter. so i can set the colour only on the initial column that the context menu appeared on. I have got around this situation in the

WPF CommandParameter binding not updating

人走茶凉 提交于 2019-11-29 04:28:50
I am trying to use Command and CommandParameter binding with Buttons in a WPF application. I have this exact same code working just fine in Silverlight so I am wondering what I have done wrong! I have a combo box and a button, where the command parameter is bound to the combobox SelectedItem: <Window x:Class="WPFCommandBindingProblem.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <StackPanel Orientation="Horizontal"> <ComboBox x:Name="combo" VerticalAlignment="Top"

How do I pass a variable as a CommandParameter

佐手、 提交于 2019-11-28 01:55:20
I'm trying to send a variable from the ViewModel as a parameter to a command. The command looks like this: public class EditPersonCommand : ICommand { private bool _CanExecute = false; public bool CanExecute(object parameter) { PersonModel p = parameter as PersonModel; CanExecuteProperty = (p != null) && (p.Age > 0); return CanExecuteProperty; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { } private bool CanExecuteProperty { get { return _CanExecute; } set { if (_CanExecute != value) { _CanExecute = value; EventHandler can_execute = CanExecuteChanged; if

How do I pass a variable as a CommandParameter

痴心易碎 提交于 2019-11-26 22:02:26
问题 I'm trying to send a variable from the ViewModel as a parameter to a command. The command looks like this: public class EditPersonCommand : ICommand { private bool _CanExecute = false; public bool CanExecute(object parameter) { PersonModel p = parameter as PersonModel; CanExecuteProperty = (p != null) && (p.Age > 0); return CanExecuteProperty; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { } private bool CanExecuteProperty { get { return _CanExecute; }