commandparameter

WPF treeview contextmenu command parameter

让人想犯罪 __ 提交于 2019-12-12 13:24:58
问题 I have TreeView with HierarchicalDataTemplate . On TreeView I have ContextMenu <TreeView Name="_packageTreeView" ItemsSource="{Binding PackageExtendedList}" Behaviors:TreeViewInPlaceEditBehavior.IsEditable="True"> <TreeView.ContextMenu> <ContextMenu StaysOpen="true"> <MenuItem Header="Добавить пакет" Height="20" Command="{Binding AddPackageCommand}" CommandParameter="{Binding ElementName=_packageTreeView, Path=SelectedItem}"> <MenuItem.Icon> <Image Source="/Resources/ManualAdd.png" Width="15"

Pass different commandparameters to same command using RelayCommand WPF

心已入冬 提交于 2019-12-12 04:38:34
问题 So, what I am trying to achieve here is to use the same command to execute some different kind of code. The way I want to distinguish between the code I want to be executed can be done using commandparameters. I just don't see how I can do it the way I want to, when I have to use the RelayCommand. This means, that I have 2 different buttons, that both uses the same command, just with different commandparameters. This is my XAML so far: <RibbonButton SmallImageSource="../Images/whatever.png"

wpf SelectedIndex CommandParameter

时光怂恿深爱的人放手 提交于 2019-12-11 10:25:02
问题 A button's Command is ExcelExportCommand and its CommandParameter is like: <Button x:Name="ExcelExport" Grid.Row="1" Height="25" Width="100" Command="{Binding ExcelExportCommand}" CommandParameter="{Binding ElementName=ListTabControl, Path=SelectedIndex}">Export to Excel</Button> How can i get the SelectedIndex through a ViewModel programmatically? I'm new to MVVM pattern and I want to verify that I had taken the right approach. Can you help? Thanks in advance 回答1: You can bind the

Pass parameter via context menu to DevExpress TreeListControl

跟風遠走 提交于 2019-12-11 05:53:04
问题 I have a TreeListControl and I will like to pass the selected row as parameter on my context menu. So my control looks like: View: <Window x:Class="WpfApplication2.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" xmlns:dxt="http://schemas.devexpress.com/winfx/2008/xaml/grid" > <dxt:TreeListControl Name="treeList" ItemsSource="{Binding MyCollection}"> <!-- Context

Different Datacontext for Command and CommandParameter

爱⌒轻易说出口 提交于 2019-12-11 03:09:30
问题 Is it possible to have a different Datacontext for a WPF Command and a CommandParameter ? <UserControl> <UserControl.Resources> <viewmodels:ListViewGridBaseViewModel x:Key="vm" /> </UserControl.Resources> <Grid> <ContentControl x:Name="currentContent" Content="{Binding Path=ListGrid}" > <ContentControl.ContextMenu> <ContextMenu > <MenuItem Command="{Binding Path=Save}" CommandParameter="{Binding ElementName=currentContent}" DataContext="{StaticResource ResourceKey=vm}" Header="Save">

Web API using command parameters is not returning any data

此生再无相见时 提交于 2019-12-08 05:36:19
问题 The web API to query the oracle database which receives the array of strings as an input parameter. I am trying to use the command parameters to avoid the SqL injection, but the below code does not throw any error but does not give the result. public class PDataController : ApiController { public HttpResponseMessage Getdetails([FromUri] string[] id) { List<OracleParameter> prms = new List<OracleParameter>(); string connStr = ConfigurationManager.ConnectionStrings["PDataConn"].ConnectionString

MVVCross: Pass an enum value as a CommandParameter for Android

孤者浪人 提交于 2019-12-08 05:00:59
问题 I want to pass an enum value as a CommandParameter. My enum is defined as: public enum MyEnum { One, Two } And in my axml I have: local:MvxBind="Click MyCommand, CommandParameter=MyEnum.One" ... local:MvxBind="Click MyCommand, CommandParameter=MyEnum.Two" and MyCommand is defined in my ViewModel as public IMvxCommand MyCommand { get { return new MvxCommand<MyEnum>(myfunction); } } private void myfunction(MyEnum p_enumParam) { switch (p_enumParam) { case MyEnum.One: doSomething1(); break; case

MVVCross: Pass an enum value as a CommandParameter for Android

[亡魂溺海] 提交于 2019-12-07 07:46:18
I want to pass an enum value as a CommandParameter. My enum is defined as: public enum MyEnum { One, Two } And in my axml I have: local:MvxBind="Click MyCommand, CommandParameter=MyEnum.One" ... local:MvxBind="Click MyCommand, CommandParameter=MyEnum.Two" and MyCommand is defined in my ViewModel as public IMvxCommand MyCommand { get { return new MvxCommand<MyEnum>(myfunction); } } private void myfunction(MyEnum p_enumParam) { switch (p_enumParam) { case MyEnum.One: doSomething1(); break; case MyEnum.Two: doSomething2(); break; } } When I run it, I get the error "System.InvalidCastException:

How do I pass entry parameters to Xamarin MVVM viewmodel

我的未来我决定 提交于 2019-12-01 11:21:59
问题 I was looking for the best way to pass entry parameters (username, password) to Xamarin MVVM viewmodel by clicking a button(in the view) with command parameters. 回答1: This is an example of passing Username and Password in Xamarin MVVM pattern. It works fine: 1)Create a LoginViewModel which will contain your commands. Make sure the ViewModel implements INotifyPropertyChanged: public class LoginViewModel:INotifyPropertyChanged { private ObservableCollection<CredentialsModel> _listOfItems=new

Binding a WPF Button CommandParameter to the Button itself in DataTemplate

纵饮孤独 提交于 2019-11-30 18:18:09
I have a DataTemplate that represents AppBar buttons that I declare through a collection of custom AppBarCommand objects. public AppBarCommand(RelayCommand command, string buttonstyle) { Command = command; ButtonStyle = buttonstyle; } <DataTemplate> <Button Command="{Binding Command}" Style="{Binding ButtonStyle, Converter={StaticResource StringNameToStyleConverter}}"/> </DataTemplate> I would like to add a CommandParameter binding, but the parameter has to be the Button itself. This is so I can set the PlacementTarget of a Callisto flyout. Is this possible? Miklós Balogh <Button Command="