commandbinding

Does Treeview use command bindings for expand/collapse?

人盡茶涼 提交于 2019-12-21 04:52:23
问题 The WPF Treeview responds to + and - keystrokes to expand and collapse nodes in the tree. Great! Is there an existing command I can bind my toolbar buttons or menu items to to perform the same actions in the treeview? I don't see anything related to expand/collapse in the stock command constants. 回答1: The TreeView handles the expansion of a TreeViewItem with the mouse by binding ToggleButton.IsChecked to TreeViewItem.IsExpanded in the ControlTemplate and handles expansion with the keyboard in

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

WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?

廉价感情. 提交于 2019-12-17 05:50:08
问题 (Note - this is a re-post as my first question got posted under wrong headline: Here Sorry!) I have a standard WPF treeview and have bound items to view model classes. I now wish to handle behaviour when items are double-clicked (opening documents visual-studio-style). I can get event-handler to fire in the control housing the treeview (xaml shown), but how do I bind to specific behaviour on the view model classes - e.g. ProjectViewModel? Preferable bound to ICommand-implementer, as this is

Modifying UI from commands - using command binding in WPF

可紊 提交于 2019-12-11 07:33:54
问题 In my WPF application I have a TextBox and a Button. The button has a command binding to a command that will do something with the text. <TextBox x:Name="_textBox"></TextBox> <Button Command="{Binding SomeCommand}" CommandParameter="{Binding ElementName=_text, Path=Text}" Content="Trigger SomeCommand" /> Now, I want the action of clicking the button to also clear the TextBox. What's the best way of doing this? I see two options: I could add a Click event too on the Button - making this clear

Command Binding to Routed Event in WPF User-control

╄→尐↘猪︶ㄣ 提交于 2019-12-11 03:43:56
问题 I want to bind Viewmodel command to Usercontrol's Routed Event. Here is the detailed explanation of what I have. I have a User Control which have one Image (which shows image) and one Button at bottom ( Button to remove Image ). I am using a Usercontrol in a ListView . In my Usercontrol's Code behind I have a RoutedEventHandler to remove the Image : public event RoutedEventHandler RemoveImage; In the window where I use this Usercontrol, I have put: <uc:ucImageListItem x:Name="ImageListItem"

Control does not refresh after CanExecute-Result does change

[亡魂溺海] 提交于 2019-12-10 13:49:25
问题 in my window I have buttons for load and save methods. I use CommandBinding and the save-button has a CanExecute property to keep the user from saving the data before it is loaded. The CanExecute-Methode is connected to a simple bool value called "canSaveXML" private void Save_CanExecute(object sender, CanExecuteRoutedEventArgs e) { if (canSaveXML == false) { e.CanExecute = false; } else { e.CanExecute = true; } e.Handled = true; } My intention is to set canSaveXML = true after the data was

Command Binding Memory Leak in WPF

核能气质少年 提交于 2019-12-10 13:15:44
问题 When i create a user control that has a CommandBinding to a RoutedUICommand im worried that i get memory leaks. scenario: Have a RoutedUICommand as a static in c class where i store my commands Implement the CommandBindings on a user control. Add the user control to the main form. Remove the user control from the main form, set the references to it to null. The canExecute of the command bindings continues to fire. I dont have a reference to the UserControl so its leaked. and it keeps firing

Can I have multiple CommandBindings for the same Command on the same control?

穿精又带淫゛_ 提交于 2019-12-10 12:43:45
问题 I have a UserControl that adds a CommandBinding to it's CommandBindings collection to handle a specific Command. Later I use this control in a window and want to add another binding to that same control to add additional behavior. The problem though, is that when I do this it seems that when I add another CommandBinding to the CommandBindings collection of a control that it replaces any binding that was already made for the same Command. So what it seems like is that a control can only have a

Can't bind command from Menu Item to a Command Binding

淺唱寂寞╮ 提交于 2019-12-10 11:58:50
问题 I've got the following xaml: <Window x:Class="Isolator.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Isolator" Height="394" Width="486" Background="Black" WindowStyle="None" WindowState="Maximized"> <Window.CommandBindings> <CommandBinding Command="Close" Executed="CommandBinding_Executed" CanExecute="CommandBinding_CanExecute"/> </Window.CommandBindings> <Window.ContextMenu> <ContextMenu> <MenuItem

CanExecute method going to false problem

空扰寡人 提交于 2019-12-10 11:33:57
问题 Well, in our application this usually works fine. But at some point, none of the CanExecute methods fire (even if I explicitly call CommandManager.InvalidateRequerySuggested(), the CanExecute methods don't run). Anyway, despite the fact that they don't run, they all get set to false, so every button, menu item, etc, bound to a CommandBinding, gets disabled until I click the MainWindow. Now, I suspect another Window causing this, when we do a certain action, a Window pops up, and then after