commandparameter

How can I pass the currently focused element name through a CommandParameter in XAML?

☆樱花仙子☆ 提交于 2020-07-23 07:32:21
问题 In my WPF MVVM application I want to be able to undo changes to individual TextBox elements using the Esc key. I've set up a command for this and I want to trigger it through XAML thus: <Window.InputBindings> <KeyBinding Command="{Binding EscKeyCommand}" CommandParameter="{Binding FocusManager.FocusedElement}" Gesture="ESC" /> </Window.InputBindings> The idea is that the CommandParameter passes the ElementName of the currently focussed TextBox (if indeed that's what's in focus) and the

How can I pass the currently focused element name through a CommandParameter in XAML?

和自甴很熟 提交于 2020-07-23 07:32:00
问题 In my WPF MVVM application I want to be able to undo changes to individual TextBox elements using the Esc key. I've set up a command for this and I want to trigger it through XAML thus: <Window.InputBindings> <KeyBinding Command="{Binding EscKeyCommand}" CommandParameter="{Binding FocusManager.FocusedElement}" Gesture="ESC" /> </Window.InputBindings> The idea is that the CommandParameter passes the ElementName of the currently focussed TextBox (if indeed that's what's in focus) and the

How can I pass the currently focused element name through a CommandParameter in XAML?

自闭症网瘾萝莉.ら 提交于 2020-07-23 07:30:11
问题 In my WPF MVVM application I want to be able to undo changes to individual TextBox elements using the Esc key. I've set up a command for this and I want to trigger it through XAML thus: <Window.InputBindings> <KeyBinding Command="{Binding EscKeyCommand}" CommandParameter="{Binding FocusManager.FocusedElement}" Gesture="ESC" /> </Window.InputBindings> The idea is that the CommandParameter passes the ElementName of the currently focussed TextBox (if indeed that's what's in focus) and the

Binding a WPF Button CommandParameter to the Button itself in DataTemplate

做~自己de王妃 提交于 2020-01-29 06:38:26
问题 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

Binding a WPF Button CommandParameter to the Button itself in DataTemplate

為{幸葍}努か 提交于 2020-01-29 06:38:05
问题 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

WPF selectedItem on Menu or get commandparameter in viewmodel

旧街凉风 提交于 2020-01-04 05:34:20
问题 I am searching for hours to fix a simple problem. I wanted to work with "SelectedItem" on my menuItems, but after hours of stackoverflow I saw that's impossible. I found a lot about "CommandParameter" but I don't understand how it works. This is what I want to do: I have a menu with "background1, background2,..." . If you select a background in the menu, I want to set that selected background as background. It's a schoolproject, so we have to use MVVM and no codebehind is allowed. How can I

CommandParameter is Nothing from ListView command binding

自古美人都是妖i 提交于 2019-12-20 02:04:44
问题 I am not succeeding in sending CommandParameter from ListView item. My code is below. <ListView x:Name="myList" ItemsSource="{Binding MyData}" <ListView.View> <GridView> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <Button Command="{Binding Path=DataContext.MyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" CommandParameter="{Binding SelectedItem, ElementName=myList}" > <Button.Content> <StackPanel Orientation="Horizontal"> <TextBlock

pass contextmenu parent as CommandParameter

戏子无情 提交于 2019-12-18 09:45:56
问题 i have a HierarchicalDataTemplate for a TreeViewItem, in the template i have a contextmenu and i want to pass as CommandParameter the ContextMenu parent - i.e the TreeViewItem owner that was right clicked at the moment, is there a way to do that? here is my template: <HierarchicalDataTemplate x:Key="ServerTemplate" DataType="{x:Type models:Server}" ItemsSource="{Binding Channels}" ItemTemplate="{StaticResource ChannelTemplate}"> <StackPanel Tag="{Binding DataContext,RelativeSource=

WPF CommandParameter binding not updating

佐手、 提交于 2019-12-18 04:18:05
问题 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=

WPF CommandParameter RelativeSource Binding

懵懂的女人 提交于 2019-12-13 12:49:25
问题 I have a ListView with a CheckBox inside of the ListView's DataTemple. I was shown how to make the Command work. I would like to capture the ListView SelectedItem to pass as a parameter to the Command, but I don't have it right... <ListView x:Name="lvReferralSource" ItemsSource="{Binding ReferralObsCollection}" Style="{StaticResource TypeListViewStyle}"> <ListView.ItemTemplate> <DataTemplate> <Grid Width="200"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width=