Search Results

Search found 4 results on 1 pages for 'inputbinding'.

Page 1/1 | 1 

  • WPF Commands firing via Keyboard shortcuts don't set the Command Parameter

    - by Aran Mulholland
    I have a command binding on the main form of my application. It is used to open details of the item that i am viewing. It has an associated keyboard shortcut. When i use the command in sub-forms i pass the object i want to open details for as a CommandParameter. This works if i attach the command to a button or a context menu, as i can specify the command parameter with a binding. However when the command is invoked as a result of a Keyboard shortcut i never get the chance to specify the parameter. How can i specify the command parameter at the sub-form level for a keyboard fired command. I need the CommandBinding with the CanExecute and Execute specified on the main form to globally handle all the open details events.

    Read the article

  • Defining InputBindings within a Style

    - by Brent
    I'm creating a WPF app using the MVVM design pattern, and I'm trying to extend the TabItem control so that it closes the tab when the user clicks the middle mouse button. I'm trying to achieve this using InputBindings, and it works very well until I try to define it within a style. I've learned that you cannot add InputBindings to a style unless you attach it using a DependencyProperty. So I followed this similar post here... and it works... almost. I can close one tab using the middle mouse button, but it won't work on any of the other tabs (all of the tabs are added at runtime and inherit the same style). So I need some help. Why would this only be working the first time, and not after? Obviously I could create a custom control that inherits from a TabItem and make it work, but I'd like to figure this out as I can see this being expanded in my projects. I'm no expert on DependencyProperties, so please help me out. Thanks! Style: <Style TargetType="{x:Type TabItem}"> <Setter Property="w:Attach.InputBindings"> <Setter.Value> <InputBindingCollection> <MouseBinding MouseAction="MiddleClick" Command="{Binding CloseCommand}"/> </InputBindingCollection> </Setter.Value> </Setter> ... </Style> Class public class Attach { public static readonly DependencyProperty InputBindingsProperty = DependencyProperty.RegisterAttached("InputBindings", typeof(InputBindingCollection), typeof(Attach), new FrameworkPropertyMetadata(new InputBindingCollection(), (sender, e) => { var element = sender as UIElement; if (element == null) return; element.InputBindings.Clear(); element.InputBindings.AddRange((InputBindingCollection)e.NewValue); })); public static InputBindingCollection GetInputBindings(UIElement element) { return (InputBindingCollection)element.GetValue(InputBindingsProperty); } public static void SetInputBindings(UIElement element, InputBindingCollection inputBindings) { element.SetValue(InputBindingsProperty, inputBindings); } }

    Read the article

  • Can I enable PreviewClick using InputBindings in WPF?

    - by No hay Problema
    I want to detect when a user clicks on an item on a listview, without using events as I do command binding and I don't like all the nonsense of the behaviours. I have tried this: <ListView x:Name="MainList" Margin="2,8,6,8" Background="Black" ItemsSource="{Binding Path=AssetsVM.Data, Mode=OneWay}" BorderBrush="{x:Null}" > <ListView.InputBindings> <MouseBinding Command="{Binding Path=AssetsVM.SelectActivo}" CommandParameter="{Binding ElementName=MainList, Path=SelectedItem}" MouseAction="LeftClick" /> </ListView.InputBindings> This works fine if I click on the listview but does not work on the items, what I need is either a way to enable "Preview" or have a MouseAction/Gesture that behaves as preview, is it possible? Thanks

    Read the article

  • Routed Command Question

    - by Andrew
    I'd like to implement a custom command to capture a Backspace key gesture inside of a textbox, but I don't know how. I wrote a test program in order to understand what's going on, but the behaviour of the program is rather confusing. Basically, I just need to be able to handle the Backspace key gesture via wpf commands while keyboard focus is in the textbox, and without disrupting the normal behaviour of the Backspace key within the textbox. Here's the xaml for the main window and the corresponding code-behind, too (note that I created a second command for the Enter key, just to compare its behaviour to that of the Backspace key): <Window x:Class="WpfApplication1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <Grid> <TextBox Margin="44,54,44,128" Name="textBox1" /> </Grid> </Window> And here's the corresponding code-behind: using System.Windows; using System.Windows.Input; namespace WpfApplication1 { /// <summary> /// Interaction logic for EntryListView.xaml /// </summary> public partial class Window1 : Window { public static RoutedCommand EnterCommand = new RoutedCommand(); public static RoutedCommand BackspaceCommand = new RoutedCommand(); public Window1() { InitializeComponent(); CommandBinding cb1 = new CommandBinding(EnterCommand, EnterExecuted, EnterCanExecute); CommandBinding cb2 = new CommandBinding(BackspaceCommand, BackspaceExecuted, BackspaceCanExecute); this.CommandBindings.Add(cb1); this.CommandBindings.Add(cb2); KeyGesture kg1 = new KeyGesture(Key.Enter); KeyGesture kg2 = new KeyGesture(Key.Back); InputBinding ib1 = new InputBinding(EnterCommand, kg1); InputBinding ib2 = new InputBinding(BackspaceCommand, kg2); this.InputBindings.Add(ib1); this.InputBindings.Add(ib2); } #region Command Handlers private void EnterCanExecute(object sender, CanExecuteRoutedEventArgs e) { MessageBox.Show("Inside EnterCanExecute Method."); e.CanExecute = true; } private void EnterExecuted(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("Inside EnterExecuted Method."); e.Handled = true; } private void BackspaceCanExecute(object sender, CanExecuteRoutedEventArgs e) { MessageBox.Show("Inside BackspaceCanExecute Method."); e.Handled = true; } private void BackspaceExecuted(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("Inside BackspaceExecuted Method."); e.Handled = true; } #endregion Command Handlers } } Any help would be very much appreciated. Thanks! Andrew

    Read the article

1