icommand

Another implementation of WPF Event to Command (with problems)

Deadly 提交于 2019-12-01 08:50:39
问题 I am looking at various implementations of hooking a ICommand up to a control's event. So for instance the GotFocus of a TextBox should call a GotFocusCommand in my View Model. I then got an idea to implement my own version (for my own learning) and it is working well, but I can only link one event to one command in the XAML. ( Basically I just use reflection to find the specified Event and then do a AddEventHandler that executes the command ) This works fine : <Button local:EventToCommand

Are there any performance implications with CanExecuteCommand?

自作多情 提交于 2019-11-30 21:16:10
What are the performance implications of using the CanExecuteCommand of the ICommand object. Is the method executed over and over again? I need to iterate through a collection of about 200 objects based on which its decided whether the button bound to the Command should be enabled? Does the CanExecuteCommand get executed repeatedly which will make my application slow The ICommand interface is the following: public interface ICommand { // two methods bool CanExecute(object parameter); void Execute(object parameter); // one event event EventHandler CanExecuteChanged; } The CanExecuteChanged

WPF Custom ICommand implementation and the CanExecuteChanged event

巧了我就是萌 提交于 2019-11-30 21:12:04
in my WPF UI, I use RoutedCommands that I refer to in my xaml via the following code: Command="viewModel:MessageListViewModel.DeleteMessagesCommand" I don't like this static link to my ViewModel class,I think this is not as nice as creating a custom ICommand implementation and use a syntax like the following Command="{Binding DeleteMessagesCommand}" Having created one, I notice one major drawback of what I've done: RoutedCommands utilize the CommandManager and (in some way that is completely opaque to me) fire the CommandManager.RequerySuggested event, so that their CanExecute Method is

Is there a way to desaturate an Image on a Button thats disabled?

佐手、 提交于 2019-11-30 16:00:49
问题 Is there a way I can desaturate images in Buttons that are disabled? eg. ICommand.CanExecute = false ? or do I need to use separate images + Style/Triggers 回答1: I'm using a special style for this, which reduces the opacity of the image when the button gets disabled (yes, this also works if the button is bound to a command). Technically, this is not desaturation, but it looks similar and it might help you derive a solution on your own: <Style x:Key="buttonImage"> <Style.Triggers> <DataTrigger

Is there a way to desaturate an Image on a Button thats disabled?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 15:43:15
Is there a way I can desaturate images in Buttons that are disabled? eg. ICommand.CanExecute = false ? or do I need to use separate images + Style/Triggers I'm using a special style for this, which reduces the opacity of the image when the button gets disabled (yes, this also works if the button is bound to a command). Technically, this is not desaturation, but it looks similar and it might help you derive a solution on your own: <Style x:Key="buttonImage"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}, AncestorLevel=1}, Path

WPF: TreeViewItem bound to an ICommand

情到浓时终转凉″ 提交于 2019-11-30 09:12:34
I am busy creating my first MVVM application in WPF. Basically the problem I am having is that I have a TreeView (System.Windows.Controls.TreeView) which I have placed on my WPF Window, I have decide that I will bind to a ReadOnlyCollection of CommandViewModel items, and these items consist of a DisplayString, Tag and a RelayCommand. Now in the XAML, I have my TreeView and I have successfully bound my ReadOnlyCollection to this. I can view this and everything looks fine in the UI. The issue now is that I need to bind the RelayCommand to the Command of the TreeViewItem, however from what I can

WPF/MVVM: Disable a Button's state when the ViewModel behind the UserControl is not yet Initialized?

与世无争的帅哥 提交于 2019-11-30 09:06:42
I have a DocumentListView.Xaml with a ListBox and 3 Buttons. Behind that UserControl sits a DocumentListViewModel with 3 Buttons and their Command Property bound to 3 RelayCommands. I have 3 Controller like AdministrationController, BillingController, ReportController. Every Controller has ObservableCollections like Customer 1 : N Order 1: N Document same for the other Controller. In one Controller I have a special binding situation. When my DocumentListViewModel is not initialized by its parent ViewModel like OrderViewModel (because no orders are loaded/exist) then my UserControl has 3

binding a command inside a listbox item to a property on the viewmodel parent

≯℡__Kan透↙ 提交于 2019-11-30 08:23:38
I've been working on this for about an hour and looked at all related SO questions. My problem is very simple: I have HomePageVieModel: HomePageVieModel +IList<NewsItem> AllNewsItems +ICommand OpenNews My markup: <Window DataContext="{Binding HomePageViewModel../> <ListBox ItemsSource="{Binding Path=AllNewsItems}"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <TextBlock> <Hyperlink Command="{Binding Path=OpenNews}"> <TextBlock Text="{Binding Path=NewsContent}" /> </Hyperlink> </TextBlock> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> The list shows fine with all the items, but

WPF Custom ICommand implementation and the CanExecuteChanged event

大憨熊 提交于 2019-11-30 05:24:08
问题 in my WPF UI, I use RoutedCommands that I refer to in my xaml via the following code: Command="viewModel:MessageListViewModel.DeleteMessagesCommand" I don't like this static link to my ViewModel class,I think this is not as nice as creating a custom ICommand implementation and use a syntax like the following Command="{Binding DeleteMessagesCommand}" Having created one, I notice one major drawback of what I've done: RoutedCommands utilize the CommandManager and (in some way that is completely

Are there any performance implications with CanExecuteCommand?

瘦欲@ 提交于 2019-11-30 05:05:12
问题 What are the performance implications of using the CanExecuteCommand of the ICommand object. Is the method executed over and over again? I need to iterate through a collection of about 200 objects based on which its decided whether the button bound to the Command should be enabled? Does the CanExecuteCommand get executed repeatedly which will make my application slow 回答1: The ICommand interface is the following: public interface ICommand { // two methods bool CanExecute(object parameter);