commandbinding

WPF Two Commands handlers, One Command

假如想象 提交于 2020-01-22 15:21:09
问题 Im deriving from a third party control. It is implementing ApplicationCommands.SelectAll. However the behaviour i want is slightly different. there is no virtual method i can override, and when i register a class handler, like so CommandManager.RegisterClassCommandBinding(typeof(MyDerivedControl), new CommandBinding(ApplicationCommands.SelectAll, new ExecutedRoutedEventHandler(OnExecutedSelectAll), new CanExecuteRoutedEventHandler(OnCanExecuteSelectAll))); My methods do not get called. The

WP8 - access datacontext of parent

此生再无相见时 提交于 2020-01-21 07:13:25
问题 How can I access the datacontext of the parent element in windows phone 8? AncestorType is not available in WP8. <ItemsControl x:Name="Elements" ItemsSource="{Binding MyList}" Grid.Row="2" Grid.Column="3"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <toolkit:WrapPanel /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button Content="e" Width="100" Height="100" Command="{Binding MyCommand" /> </DataTemplate> </ItemsControl.ItemTemplate> <

WPF Binding FrameworkElement event to command

混江龙づ霸主 提交于 2020-01-14 03:29:11
问题 How can I bind a UserControl 's FrameworkElement event to a view model command? I use MVVM and Prism so clear separation between the view the view-model would be nice. I'd tried multiple things, and none of them worked: <i:Interaction.Triggers> <i:EventTrigger EventName="FrameworkElement.Unloaded"> <i:InvokeCommandAction Command="{Binding Unloaded}" /> </i:EventTrigger> </i:Interaction.Triggers> also using this tutorial http://blog.functionalfun.net/2008/09/hooking-up-commands-to-events-in

WPF command binding for custom UserControl

跟風遠走 提交于 2020-01-06 07:00:12
问题 I have a custom Button as follows: <UserControl...> <Button HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Viewbox Stretch="Uniform" Grid.Column="0"> <TextBlock x:Name="numCopyTB" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=Text}"/> </Viewbox> <Viewbox Grid.Column="1"> <TextBlock Style="

Implement custom Copy and Paste in WPF DataGrid which works when there are no rows in it

爱⌒轻易说出口 提交于 2020-01-01 09:38:50
问题 I need to implement a custom copy + cut + paste for data (not text or CSV) to be copied between grids in a WPF application. Using standard ApplicationCommands and defining CommandBinding works really well but only if the DataGrid contains at least 1 row of data and when it's selected. When there are no rows or focus is not on any of them, all commands are disabled. To fix the problem I tried calling CommandManager.InvalidateRequerySuggested() and setting Focusable=true and/or FocusManager

Command binding is not propagating for control into a DataTemplate of ItemTemplate

我与影子孤独终老i 提交于 2019-12-25 07:59:57
问题 For Command "CommandZoomIn", CanExecute and Execute do not occurs for controls defined into the ListBox ItemTemplate. GraphLcView method "CanExecute" and "Execute" are both called when GraphLcView UserControl is defined directly as child of AnalysisView, but both methods are never called when they are added as Item DataTemplate of a ListBox ItemTemplate. The button with the command is defined in my top level window into a Ribbon. Simplified hierarchy: (Working) Top Level window ->

How can I disable the default RichTextBox command for Ctrl+1?

久未见 提交于 2019-12-25 06:46:57
问题 Snoop shows that the command is "ApplySingleSpace", but when I try disabling it via the method described in this article . Like this: <RichTextBox.CommandBindings> <CommandBinding Command="ApplySingleSpace" CanExecute="BlockTheCommand"/> </RichTextBox.CommandBindings> . private void BlockTheCommand(object sender, CanExecuteRoutedEventArgs e) { e.CanExecute = false; e.Handled = true; } My app crashes because there is no ApplySingleSpace command. ApplySingleSpace is not in the EditingCommands

How to use the text of a routed command as button content

喜欢而已 提交于 2019-12-23 10:57:06
问题 I have a button on a view that is bound via a RoutedUICommand to a command defined in the ViewModel. The XAML code excerpt from the view: <Button Content="Login" Command="{Binding Login}" /> In the View's CodeBehind I add the command binding from the ViewModel to the view's binding collection: this.CommandBindings.Add( viewModel.LoginCommandBinding ); The ViewModel itself implements the command: public class LoginViewModel:ViewModelBase { public ICommand Login { get; private set; } public

How to use the text of a routed command as button content

*爱你&永不变心* 提交于 2019-12-23 10:57:00
问题 I have a button on a view that is bound via a RoutedUICommand to a command defined in the ViewModel. The XAML code excerpt from the view: <Button Content="Login" Command="{Binding Login}" /> In the View's CodeBehind I add the command binding from the ViewModel to the view's binding collection: this.CommandBindings.Add( viewModel.LoginCommandBinding ); The ViewModel itself implements the command: public class LoginViewModel:ViewModelBase { public ICommand Login { get; private set; } public

WPF CommandParameter Binding Problem

让人想犯罪 __ 提交于 2019-12-22 05:57:26
问题 I'm having some trouble understanding how command parameter binding works. When I create an instance of the widget class before the call to InitializeComponent it seems to work fine. Modifications to the parameter(Widget) in the ExecuteCommand function will be "applied" to _widget. This is the behavior I expected. If the instance of _widget is created after InitializeComponent, I get null reference exceptions for e.Parameter in the ExecuteCommand function. Why is this? How do I make this work