标签: commandparameter

将当前窗口作为CommandParameter传递

如何将当前窗口作为参数传递给命令?

我喜欢在XAML-markup中执行此操作:

<Button Command="CommandGetsCalled" CommandParameter="-this?-" />
Run Code Online (Sandbox Code Playgroud)

wpf binding commandparameter

24
推荐指数
3
解决办法
2万
查看次数

如何在Xamarin.Forms页面中从XAML传递Button作为CommandParameter?

我想将Xamarin.Forms.Button它自己Command作为CommandParameter我的ViewModel 传递给它.我知道如何从背后的代码实现这一点,例如......

XAML (由于简洁而遗漏了大多数属性)

<Button x:Name="myButton"
    Text="My Button"
    Command="{Binding ButtonClickCommand}"/>
Run Code Online (Sandbox Code Playgroud)

XAML.cs

public partial class MyTestPage
{
    public MyTestPage()
    {
        InitializeComponent();

        myButton.CommandParameter = myButton;
    }
}
Run Code Online (Sandbox Code Playgroud)

视图模型

public class MyViewModel : ViewModelBase
{
    public MyViewModel()
    {
        ButtonClickCommand = new Command(
            (parameter) =>
            {
                var view = parameter as Xamarin.Forms.Button;
                if (view != null)
                {
                    // Do Stuff
                }
            });
    }

    public ICommand ButtonClickCommand { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)

......但是可以CommandParameter在XAML中声明它吗?或者换句话说,将参数设置为按钮本身的绑定语法是什么?

<Button x:Name="myButton"
        Text="My …
Run Code Online (Sandbox Code Playgroud)

c# xaml commandparameter xamarin.forms

13
推荐指数
3
解决办法
2万
查看次数

将WPF Button CommandParameter绑定到DataTemplate中的Button本身

我有一个DataTemplate代表AppBar按钮,我通过自定义AppBarCommand对象的集合声明.

  public AppBarCommand(RelayCommand command, string buttonstyle)
  {
     Command = command;
     ButtonStyle = buttonstyle;
  }

<DataTemplate>
   <Button Command="{Binding Command}"
           Style="{Binding ButtonStyle, Converter={StaticResource StringNameToStyleConverter}}"/>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)

我想添加一个CommandParameter绑定,但参数必须是Button本身.这样我就可以设置Call​​isto弹出窗口的PlacementTarget.这可能吗?

c# wpf binding datatemplate commandparameter

11
推荐指数
2
解决办法
3万
查看次数

MVVM-Light =>将命令参数和EventArgs传递给Command

MVVM-Light Toolkit在Silverlight 5中使用,我试图找到一种方法在事件到命令行为中将Command Parameters AND 传递EventArgs给ViewModel.

我没有找到一个职位提示路过的EventArgs作为命令参数,但在我的情况,我想用EventArgsCommand Parameter无论是在视图模型.

有人可以帮忙吗?

c# silverlight commandparameter mvvm-light eventtocommand

9
推荐指数
1
解决办法
5650
查看次数

如何正确绑定菜单项?

如何正确绑定动态创建的菜单项列表.我尝试了几件事,但似乎都没有效果.我得到了正确的名单,但我的ViewSwitchCommand似乎没有正确启动.

<MenuItem Foreground="White" Header="Names" ItemsSource="{Binding Player.ToonNames}" Command="{Binding ViewSwitchCommand}" CommandParameter="{Binding Header}"/>
Run Code Online (Sandbox Code Playgroud)

但是,如果我不动态地这样做,那么一切正常,可以让它工作

<MenuItem Foreground="White" Header="Names">
<MenuItem Foreground="Black" Header="Chat" Command="{Binding ViewSwitchCommand}"     CommandParameter="player1" />
<MenuItem Foreground="Black" Header="Craft" Command="{Binding ViewSwitchCommand}" CommandParameter="player2" />
</MenuItem>
Run Code Online (Sandbox Code Playgroud)

命令参数需要一个字符串..不确定是不是它...希望这是一个简单的我只是忽略

data-binding wpf mvvm menuitem commandparameter

8
推荐指数
1
解决办法
1万
查看次数

如何将变量作为CommandParameter传递

我正在尝试将ViewModel中的变量作为参数发送到命令.该命令如下所示:

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 (can_execute != null)
           {
              can_execute.Invoke(this, EventArgs.Empty);
           }
        }
     }
  }
} …
Run Code Online (Sandbox Code Playgroud)

c# wpf command mvvm commandparameter

8
推荐指数
2
解决办法
3万
查看次数

WPF CommandParameter绑定不更新

我试图在WPF应用程序中使用Command和CommandParameter与Buttons绑定.我有这个完全相同的代码在Silverlight中工作正常,所以我想知道我做错了什么!

我有一个组合框和一个按钮,其中命令参数绑定到组合框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" />
        <Button Content="Do Something" Command="{Binding Path=TestCommand}"
                CommandParameter="{Binding Path=SelectedItem, ElementName=combo}"
                VerticalAlignment="Top"/>        
    </StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)

背后的代码如下:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        combo.ItemsSource = new List<string>(){
            "One", "Two", "Three", "Four", "Five"
        };

        this.DataContext = this;

    }

    public TestCommand TestCommand
    {
        get
        {
            return new TestCommand();
        }
    }

}

public class TestCommand : ICommand
{
    public bool CanExecute(object parameter)
    {
        return parameter is string && …
Run Code Online (Sandbox Code Playgroud)

wpf binding command commandparameter

7
推荐指数
1
解决办法
6548
查看次数

通过键绑定从Datagrid传递命令参数

我有一个特定的wpf问题.我正在尝试从Datagrid中删除一行,方法是定义一个Keybinding,它将Datagrid的选定行作为CommandParameter传递给Command.

这是我的Keybinding:

<UserControl.Resources >
    <Commands:CommandReference x:Key="deleteKey" Command="{Binding DeleteSelectedCommand}"/>
</UserControl.Resources>

<UserControl.InputBindings>
    <KeyBinding Key="D" Modifiers="Control" Command="{StaticResource deleteKey}"/>
</UserControl.InputBindings>
Run Code Online (Sandbox Code Playgroud)

我知道这基本上有效,因为我可以调试到DeleteSelectedCommand.但是有一个异常,因为DeleteSelectedCommand会将Datagrid的一行预先删除为Call Parameter.

如何通过Keybinding传递SelectedRow?

我想在可能的情况下仅在XAML中执行此操作,而不更改Code Behind.

wpf xaml key-bindings commandparameter

4
推荐指数
2
解决办法
1万
查看次数

Silverlight:如何将True传递给CommandParameter?

我怎么True转到CommandParameter

目前我势在必须添加Boolean.True到资源字典中,但这似乎是一种笨拙的方式.

silverlight command commandparameter

4
推荐指数
3
解决办法
3802
查看次数

如何在按钮中传递参数并在后面的代码中获取值,根据windows phone 7中的参数值重定向到另一个页面?

我在想如果windows phone 7按钮事件类似于使用C#的ASP.NET开发,类似于按钮,我在XAML中将值设置为commandparameter,在后面的代码中,我得到命令参数并重定向页面.

我没有找到任何关于按钮事件处理的好例子,有什么建议吗?

谢谢.

parameters button commandparameter windows-phone-7

4
推荐指数
2
解决办法
1万
查看次数