Search Results

Search found 30 results on 2 pages for 'commandbinding'.

Page 1/2 | 1 2  | Next Page >

  • CommandBinding CanExecute always null

    - by developer
    Hi All, I am using CommandBinding to display visibility of a button. Below is my code <UserControl.CommandBindings> <CommandBinding Command="{x:Static local:AttendeePanel.LaunchAttEditor}" Executed="LaunchAttEditor_Executed" CanExecute="CanCreateProfile"/> </UserControl.CommandBindings> <Button Content="Create Profile" Command="local:LaunchEditor" CommandParameter="{Binding Profile}" Name="BtnCreate"> My problem is that CanExecute method always gets null as parameter even though I am binding the parameter to Profile. Is there a way I can set Data Context? or is this because the canexecute runs before data load?

    Read the article

  • CommandBinding broken in inner Custom Control when nesting two Custom Controls of the same type.

    - by Fredrik Eriksson
    I've done a Custom Control in form of a GroupBox but with an extra header which purpose is to hold a button or a stackpanel with buttons at the other side. I've added the a Dependency Property to hold the extra header and I've connected the customized template. Everything works fine until I put one of these controls in another one. Now the wierd stuff begins(at least in my eyes xP), the command binding in the inner control simply isn't set. I tried to use Snoop to gather some data, the see if the inherits is broken and when I clicked on the buttons which isn't doing what I want it to, boom, breakpoint triggered. So in some wierd way the Command isn't set until something that I don't know what it is, happens, which snoops triggers. I've also tried to put the buttons in the regular Header property and that works fine, but not with my own made. I could just switch places with them to make it like I want but now I'm curious to know where the problem lies... Now I wonder, what can I've missed? The control class: public class TwoHeaderedGroupBox : GroupBox { static TwoHeaderedGroupBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(TwoHeaderedGroupBox), new FrameworkPropertyMetadata(typeof(TwoHeaderedGroupBox))); } public static DependencyProperty HeaderTwoProperty = DependencyProperty.Register("HeaderTwo", typeof(object), typeof(TwoHeaderedGroupBox), new FrameworkPropertyMetadata()); public object HeaderTwo { get { return (object)GetValue(HeaderTwoProperty); } set { SetValue(HeaderTwoProperty, value);} } } And here is the Template (which by the way is created by blend from the beginning): <ControlTemplate TargetType="{x:Type Controls:TwoHeaderedGroupBox}"> <Grid SnapsToDevicePixels="true"> <Grid.ColumnDefinitions> <ColumnDefinition Width="6"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="6"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="6"/> </Grid.RowDefinitions> <Border BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Grid.Column="0" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3"/> <Border x:Name="Header" Grid.Column="1" Padding="3,1,3,0" Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Center"> <ContentControl Content="{TemplateBinding Header}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> <ContentPresenter Grid.ColumnSpan="2" Grid.Column="1" Margin="{TemplateBinding Padding}" Grid.Row="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="4" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3"> <Border.OpacityMask> <MultiBinding ConverterParameter="7" Converter="{StaticResource BorderGapMaskConverter}"> <Binding ElementName="Header" Path="ActualWidth"/> <Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/> <Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/> </MultiBinding> </Border.OpacityMask> <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3"> <Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/> </Border> </Border> <Border x:Name="HeaderTwo" Grid.Column="2" Padding="3,5,3,5" Grid.Row="0" Grid.RowSpan="2" HorizontalAlignment="Right"> <ContentControl Content="{TemplateBinding HeaderTwo}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" DataContext="{TemplateBinding DataContext}"/> </Border> </Grid> </ControlTemplate>

    Read the article

  • 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

  • WPF Two Commands handlers, One Command

    - by Aran Mulholland
    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 third party control i am deriving from is marking e.Handled=true; in its command handlers ( i know this cause i have seen the source, but i cant modify it ) What can i do?

    Read the article

  • ApplicationCommand.Paste happens twice

    - by Carlo
    Hi, well this is driving me crazy. We have a command like so: <CommandBinding Command="ApplicationCommands.Paste" CanExecute="HasClipboardData" Executed="OnPasteExecuted"/> And the code for OnPasteExecuted is this: private void OnPasteExecuted(object sender, ExecutedRoutedEventArgs e) { CurrentView.Paste(); e.Handled = true; } That code gets executed twice, and I have no idea why, we also have the other commands: Cut, Copy, Undo, Redo, those work just fine, the problem is only with Paste. Let me know if you have any idea of what could be going on. Thanks!

    Read the article

  • How to Bind a Command in WPF

    - by MegaMind
    Sometimes we used complex ways so many times, we forgot the simplest ways to do the task. I know how to do command binding, but i always use same approach. Create a class that implements ICommand interface and from the view model i create new instance of that class and binding works like a charm. This is the code that i used for command binding public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); DataContext = this; testCommand = new MeCommand(processor); } ICommand testCommand; public ICommand test { get { return testCommand; } } public void processor() { MessageBox.Show("hello world"); } } public class MeCommand : ICommand { public delegate void ExecuteMethod(); private ExecuteMethod meth; public MeCommand(ExecuteMethod exec) { meth = exec; } public bool CanExecute(object parameter) { return false; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { meth(); } } But i want to know the basic way to do this, no third party dll no new class creation. Do this simple command binding using a single class. Actual class implements from ICommand interface and do the work.

    Read the article

  • Silverlight Cream for November 24, 2011 -- #1173

    - by Dave Campbell
    In this Thanksgiving Day Issue: Andrea Boschin, Samidip Basu, Ollie Riches, WindowsPhoneGeek, Sumit Dutta, Dhananjay Kumar, Daniel Egan, Doug Mair, Chris Woodruff, and Debal Saha.Happy Thanksgiving Everybody! Above the Fold: Silverlight: "Silverlight CommandBinding with Simple MVVM Toolkit" Debal Saha WP7: "How many pins can Bing Maps handle in a WP7 app - part 3" Ollie Riches Shoutouts: Michael Palermo's latest Desert Mountain Developers is up Michael Washington's latest Visual Studio #LightSwitch Daily is up From SilverlightCream.com:Windows Phone 7.5 - Play with musicAndrea Boschin's latest WP7 post is up on SilverlightShow... he's talking about the improvements in the music hub and also the programmability of musicOData caching in Windows PhoneSamidip Basu has an OData post up on SilverlightShow also, and he's talking about data caching strategies on WP7How many pins can Bing Maps handle in a WP7 app - part 3Ollie Riches has part 3 of his series on Bing Maps and pins... sepecifically how to deal with a large number of them... after going through discussing pins, he is suggesting using a heat map which looks pretty darn good, and renders fast... except when on a device :(Improvements in the LongListSelector Selection with Nov `11 release of WP ToolkitWindowsPhoneGeek's latest is this tutorial on the LongListSelector in the WP Toolkit... check out the previous info in his free eBook to get ready then dig into this tutorial for improvements in the control.Part 25 - Windows Phone 7 - Device StatusSumit Dutta's latest post is number 25 in his WP7 series, and time out he's digging into device status in the Microsoft.Phone.Info namespaceVideo on How to work with Picture in Windows Phone 7Dhananjay Kumar's latest video tutorial on WP7 is up, and he's talking about working with Photos.Live Tiles–Windows Phone WorkshopDaniel Egan has the video up of a Windows Phone Workshop done earlier this week on Live Tiles31 Days of Mango | Day #15: The Progress BarDoug Mair shares the show with Jeff Blankenburg in Jeff's Day 15 in his 31 Day quest of Mango, talking about the progressbar: Indeterminate and Determinate Modes abound31 Days of Mango | Day #14: Using ODataChris Woodruff has a guest spot on Jeff Blankenburg's 31 Days series with this post on OData... long detailed tutorial with all the codeSilverlight CommandBinding with Simple MVVM ToolkitDebal Saha has a nice detailed tutorial up on CommandBinding.. he's using the SimpleMVVM Toolkit and shows downloading and installing itStay in the 'Light!Twitter SilverlightNews | Twitter WynApse | WynApse.com | Tagged Posts | SilverlightCreamJoin me @ SilverlightCream | Phoenix Silverlight User GroupTechnorati Tags:Silverlight    Silverlight 3    Silverlight 4    Windows PhoneMIX10

    Read the article

  • Workarounds for supporting MVVM in the Silverlight ContextMenu service

    - by cibrax
    As I discussed in my last post, some of the Silverlight controls does not support MVVM quite well out of the box without specific customizations. The Context Menu is another control that requires customizations for enabling data binding on the menu options. There are a few things that you might want to expose as view model for a menu item, such as the Text, the associated icon or the command that needs to be executed. That view model should look like this, public class MenuItemModel { public string Name { get; set; } public ICommand Command { get; set; } public Image Icon { get; set; } public object CommandParameter { get; set; } } This is how you can modify the built-in control to support data binding on the model above, public class CustomContextMenu : ContextMenu { protected override DependencyObject GetContainerForItemOverride() { CustomMenuItem item = new CustomMenuItem(); Binding commandBinding = new Binding("Command"); item.SetBinding(CustomMenuItem.CommandProperty, commandBinding);   Binding commandParameter = new Binding("CommandParameter"); item.SetBinding(CustomMenuItem.CommandParameterProperty, commandParameter);   return item; } }   public class CustomMenuItem : MenuItem { protected override DependencyObject GetContainerForItemOverride() { CustomMenuItem item = new CustomMenuItem();   Binding commandBinding = new Binding("Command"); item.SetBinding(CustomMenuItem.CommandProperty, commandBinding);   return item; } } The change is very similar to the one I made in the TreeView for manually data binding some of the Menu item properties to the model. Once you applied that change in the control, you can define it in your XAML like this. <toolkit:ContextMenuService.ContextMenu> <e:CustomContextMenu ItemsSource="{Binding MenuItems}"> <e:CustomContextMenu.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" > <ContentPresenter Margin="0 0 4 0" Content="{Binding Icon}" /> <TextBlock Margin="0" Text="{Binding Name, Mode=OneWay}" FontSize="12"/> </StackPanel> </DataTemplate> </e:CustomContextMenu.ItemTemplate> </e:CustomContextMenu> </toolkit:ContextMenuService.ContextMenu> The property MenuItems associated to the “ItemsSource” in the parent model just returns a list of supported options (menu items) in the context menu. this.menuItems = new MenuItemModel[] { new MenuItemModel { Name = "My Command", Command = new RelayCommand(OnCommandClick), Icon = ImageLoader.GetIcon("command.png") } }; The only problem I found so far with this approach is that the context menu service does not support a HierarchicalDataTemplate in case you want to have an hierarchy in the context menu (MenuItem –> Sub menu items), but I guess we can live without that.

    Read the article

  • Disabling Navigation Flicks in WPF

    - by Brian Genisio's House Of Bilz
    I am currently working on a multi-touch application using WPF.  One thing that has been irritating me with this development is an automatic navigation forward/back command that is bound to forward and backwards flicks.  Many of my touch-based interactions were being thwarted by gestures picked up by WPF as navigation.  I just wanted to disable this behavior. My programmatic back/forward calls are not affected by this change, which is nice.  Here is how I did it:  In my main window, I added the following command bindings:<NavigationWindow.CommandBindings> <CommandBinding Command="NavigationCommands.BrowseBack" Executed="DoNothing" /> <CommandBinding Command="NavigationCommands.BrowseForward" Executed="DoNothing" /> </NavigationWindow.CommandBindings> Then, the DoNothing method in the code-behind does nothing:private void DoNothing(object sender, ExecutedRoutedEventArgs e) { } There may be a better way to do this, but I haven’t found one.

    Read the article

  • How to make route-commands execute in the global application scope rather than locally in a page or

    - by Shimmy
    Hello! I created a window that contains a frame, and above the frame it contains a button that its Command property is set to "Refresh". In the page shown in the frame, I set a CommandBinding for Refresh. I want that when the 'Refresh' command is executed it should be caught by the page Refresh_Executed event-handler set in the CommandBinding. In other words, Is there a way to set global Commands that are targeted for the entire application scope and execute everywhere they're bound?

    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

  • Howto bind a RoutedCommand in a child?

    - by Wouter
    I am having trouble binding a Command that is generated up the UI tree to a control. The following example illustrates my point, the CommandBinding in Grid does not act on the InputBindings in Window. Maybe I do not understand the point of commands, but I would like to have a nice solution for child controls to act on user input on the Window (any control on the Window). <Window x:Class="SilverFit.Menu.Wpf.WpfWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Window.InputBindings> <KeyBinding Command="Close" Key="Escape"/> <MouseBinding Command="Close" MouseAction="RightClick" /> </Window.InputBindings> <Grid Name="grid"> <Grid.CommandBindings> <CommandBinding Command="Close" Executed="Close"/> </Grid.CommandBindings> </Grid> </Window>

    Read the article

  • How to use command bindings in user controls in wpf?

    - by Sam
    In MainWindow the commandbinding works fine. In UserControl1 it doesnt work. Note the datacontext is set correctly as is evidenced by the content of the button which is the result of a binding. I am not trying to bind the command in the usercontrol to a command in mainwindow or any other such trickery. I am just trying to replicate what I did in MainWindow in UserControl1. // MainWindow xaml <StackPanel> <Button Content="Click Here" Command="{Binding ClickHereCommand}" Height="25" Width="90"></Button> <local:UserControl1></local:UserControl1> </StackPanel> // MainWindow public partial class MainWindow : Window { public static RoutedCommand ClickHereCommand { get; set; } public MainWindow() { InitializeComponent(); this.DataContext = this; ClickHereCommand = new RoutedCommand(); CommandBindings.Add(new CommandBinding(ClickHereCommand, ClickHereExecuted)); } public void ClickHereExecuted(object sender, ExecutedRoutedEventArgs e) { System.Windows.MessageBox.Show("hello"); } } // UserControl1 xaml <UserControl x:Class="CommandBindingTest.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" x:Name="root"> <Grid DataContext="{Binding ElementName=root}" > <Button Content="{Binding ButtonContent}" Command="{Binding ClickHereCommand}" Height="25" Width="90"></Button> </Grid> </UserControl> // UserControl1 public partial class UserControl1 : UserControl, INotifyPropertyChanged { private string _ButtonContent; public string ButtonContent { get { return _ButtonContent; } set { if (_ButtonContent != value) { _ButtonContent = value; OnPropertyChanged("ButtonContent"); } } } public static RoutedCommand ClickHereCommand { get; set; } public UserControl1() { InitializeComponent(); ClickHereCommand = new RoutedCommand(); CommandBindings.Add(new CommandBinding(ClickHereCommand, ClickHereExecuted)); ButtonContent = "Click Here"; } public void ClickHereExecuted(object sender, ExecutedRoutedEventArgs e) { System.Windows.MessageBox.Show("hello from UserControl1"); } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(name)); } } #endregion }

    Read the article

  • command binding for ribbon control

    - by kartik
    I'm trying to use the Microsoft ribbon control programatically using C#. Everything is fine but I'm unable to bind the command through the RibbonCommand. Can anyone give me an example of how to do this? My actual code is: Ribbon rbn = new Ribbon(); RibbonTab file = new RibbonTab(); file.Name = "file"; file.Label = "FILE"; RibbonTab edit = new RibbonTab(); edit.Name = "edit"; edit.Label = "Edit"; RibbonGroupPanel rbgp = new RibbonGroupPanel(); RibbonGroup rbg = new RibbonGroup(); RibbonButton rbtn = new RibbonButton(); rbtn.Content = "New"; RibbonCommand rcomnd = new RibbonCommand(); rcomnd.LabelTitle = "NEW"; rcomnd.ToolTipDescription = "THIS IS NEW"; rcomnd.LargeImageSource = imgSource; rcomnd.Execute(rbtn, rbtn); rbtn.IsEnabled = true; //rcomnd.SmallImageSource = imgSource; rcomnd.CanExecute +=new CanExecuteRoutedEventHandler(rcomnd_CanExecute); rcomnd.Executed +=new ExecutedRoutedEventHandler(rcomnd_Executed); CommandBinding cmdb = new CommandBinding(ApplicationCommands.New); cmdb.Command = ApplicationCommands.New; cmdb.Executed +=new ExecutedRoutedEventHandler(cmdb_Executed); CommandBind.Add(cmdb); //rcomnd.Executed += new ExecutedRoutedEventHandler(OnAddNewEntry);*/ rbtn.Click +=new System.Windows.RoutedEventHandler(rbtn_Click); rbtn.Command = rcomnd; But the bindings are not working and the button is not enabled.

    Read the article

  • [WPF] How to register to/listen to richtextbox command's?

    - by Liewe
    I'm creating a simple editor within our application using the WPF RichTextBox. Above it I've added the reguslar buttons like Bold, Italic, etc. These buttons use the RichTextBox's commands to set these properties, but next to these buttons, the commands also get send with CTRL+B, CTRL+I, etc. I want these buttons to represent the current state of the RichTextBox at the cursor. I already found out how to get this state and it works when I update this state on the SelectionChanged event. This event ofcourse isn't fired when Bold is toggled so there is no direct feedback. I would like to know if there is a way to listen to the commands being called, without affecting its original behaviour or some other ideas to solve my problems. I tried listening to the command the following way: CommandBinding boldBinding = new CommandBinding(EditingCommands.ToggleBold, CommandExecuted); _richTextBox.CommandBindings.Add(boldBinding); and private void CommandExecuted(object sender, ExecutedRoutedEventArgs e) { UpdateProperties(); e.Handled = false; } This did update the properties, but the RichTextBox didn't seem to receive the command anymore. I also tried to make my own commands on the control containing the RichTextBox, but when CTRL+B is pressed when the RichTextBox has focus, the original RichTextBox commands are called instead of the new one. Many thanks in advance! Liewe

    Read the article

  • [WPF] How to register to/listen to richtextbox commando's?

    - by Liewe
    I'm creating a simple editor within our application using the WPF RichTextBox. Above it I've added the reguslar buttons like Bold, Italic, etc. These buttons use the RichTextBox's commands to set these properties, but next to these buttons, the commands also get send with CTRL+B, CTRL+I, etc. I want these buttons to represent the current state of the RichTextBox at the cursor. I already found out how to get this state and it works when I update this state on the SelectionChanged event. This event ofcourse isn't fired when Bold is toggled so there is no direct feedback. I would like to know if there is a way to listen to the commands being called, without affecting its original behaviour or some other ideas to solve my problems. I tried listening to the command the following way: CommandBinding boldBinding = new CommandBinding(EditingCommands.ToggleBold, CommandExecuted); _richTextBox.CommandBindings.Add(boldBinding); and private void CommandExecuted(object sender, ExecutedRoutedEventArgs e) { UpdateProperties(); e.Handled = false; } This did update the properties, but the RichTextBox didn't seem to receive the command anymore. I also tried to make my own commands on the control containing the RichTextBox, but when CTRL+B is pressed when the RichTextBox has focus, the original RichTextBox commands are called instead of the new one. Many thanks in advance! Liewe

    Read the article

  • Assigning an event or command to a DataTemplate in ResourceDictionary

    - by Scott
    I have the following class: public class Day { public int Date { get; set; } public String DayName { get; set; } public Day() { } public Day(int date, string dayName) { Date = date; DayName = dayName; CommandManager.RegisterClassCommandBinding(typeof(Day), new CommandBinding(DayClick, new ExecutedRoutedEventHandler(OnExecutedDayClick), new CanExecuteRoutedEventHandler(OnCanExecuteDayClick))); } public static readonly RoutedCommand DayClick = new RoutedCommand("DayClick", typeof(Day)); private static void OnCanExecuteDayClick(object sender, CanExecuteRoutedEventArgs e) { ((Day)sender).OnCanExecuteDayClick(e); } private static void OnExecutedDayClick(object sender, ExecutedRoutedEventArgs e) { ((Day)sender).OnExecutedDayClick(e); } protected virtual void OnCanExecuteDayClick(CanExecuteRoutedEventArgs e) { e.CanExecute = true; e.Handled = false; } protected virtual void OnExecutedDayClick(ExecutedRoutedEventArgs e) { string content = String.Format("Day {0}, which is {1}, was clicked.", Date.ToString(), DayName); MessageBox.Show(content); e.Handled = true; } } I am using the following DataTemplate (that is in a ResourceDictionary) to render it: <DataTemplate DataType="{x:Type local:Day}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <Rectangle Grid.ColumnSpan="2" x:Name="rectHasEntry" Fill="WhiteSmoke"/> <TextBlock Grid.Column="0" x:Name="textBlockDayName" Text="{Binding DayName}" FontFamily="Junction" FontSize="11" Background="Transparent" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,2,0,0"/> <TextBlock Grid.Column="1" x:Name="textBlockDate" Text="{Binding Date}" FontFamily="Junction" FontSize="11" Background="Transparent" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,2,0,0"/> <Rectangle Grid.ColumnSpan="2" x:Name="rectMouseOver" Fill="#A2C0DA" Opacity="0" Style="{StaticResource DayRectangleMouseOverStyle}"> </Rectangle> </Grid> </DataTemplate> No problems so far, I can get it on screen. What I want to be able to do is assign a Command, or use an event, so that when the user clicks on the Day it will notify the parent of the Day object that it has been clicked. I've tried the following: <Rectangle.CommandBindings> <CommandBinding Command="{x:Static local:Day.NextDay}" Executed="{x:Static local:Day.OnExecutedDayClick}" CanExecute="{x:Static local:Day.OnCanExecuteDayClick}"/> </Rectangle.CommandBindings> to try and bind the commands that are in the Day class but it didn't work. I got an error stating: 'ResourceDictionary' root element requires a x:Class attribute to support event handlers in the XAML file. Either remove the event handler for the Executed event, or add a x:Class attribute to the root element. Which I think means that there is no code-behind file for a ResourceDictionary, or something to that effect. In any event, I'm not sure if I should be using Commands here, or somehow tying events to the Rectangle in question, or if this is even possible. I've seen various places where it sure looks like it's possible, I'm just unable to translate what I'm seeing into something that actually works, hence this post. Thanks in advance.

    Read the article

  • Adding programatically a command to a listbox in WPF

    - by ajtp
    In my WPF application there is a listbox with items. The listbox is populated via a xmldataprovider from XAML and then binding it to Itemssource property of the listbox. Well, from XAML, I bind a comand to the listbox by doing: <ListBox.CommandBindings> <CommandBinding Command="{x:Static local:mainApp.MyCmd}" CanExecute="CanExecute" Executed ="Executed" /> </ListBox.CommandBindings> but I don't know how to programatically bind a command to each listboxitem. How to do it? Thanks in advance.

    Read the article

  • Context Menu SourceControl Error

    - by developer
    Hi All, I am trying to use contextmenu in my textbox control and I want to bind the textbox value to the value selected in context menu,below is my code <Window.CommandBindings> <CommandBinding Command="local:MyPanel.ChangeTextboxValue" Executed="ChangeTextboxValue_Executed"/> </Window.CommandBindings> CODE-BEHIND public static RoutedUICommand ChangeTextboxValue = new RoutedUICommand ("ChangeTextboxValue", "ChangeTextboxValue", typeof(MyPanel)); private void ChangeTextboxValue_Executed(object sender, ExecutedRoutedEventArgs e) { string oldvalue = Convert.ToString(e.Parameter); (((sender as MenuItem).Parent as ContextMenu).PlacementTarget as TextBox).Text = oldvalue; } oldvalue is the value I want the textbox controls value to change to. I am trying to use above code but it gives me the error, 'Object reference not set to an instance of object'. I tried to debug the app and I get ContextMenu as null.. .Any ideas why??

    Read the article

  • WPF ICommand over a button

    - by toni
    Hi, I have implemented a custom IComand class for one of my buttons. The button is placed in a page 'MyPage.xaml' but its custom ICommand class is placed in another class, not in the MyPage code behind. Then from XAML I want to bind the button with its custom command class and then I do: MyPage.xaml: <Page ...> <Page.CommandBindings> <CommandBinding Command="RemoveAllCommand" CanExecute="CanExecute" Executed="Execute" /> </Page.CommandBindings> <Page.InputBindings> <MouseBinding Command="RemoveAllCommand" MouseAction="LeftClick" /> </Page.InputBindings> <...> <Button x:Name="MyButton" Command="RemoveAllCommand" .../> <...> </Page> and the custom command button class: // Here I derive from MyPage class because I want to access some objects from // Execute method public class RemoveAllCommand : MyPage, ICommand { public void Execute(Object parameter) { <...> } public bool CanExecute(Object parameter) { <...> } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } } My problem is how to say MyPage.xaml that Execute and CanExecute methods for the button is in another class and not the code behind where is placed the button. How to say these methods are in RemoveAllCommand Class in XAML page. Also I want to fire this command when click mouse event is produced in the button so I do an input binding, is it correct? Thanks

    Read the article

  • WPF ICommand over a button

    - by toni
    I have implemented a custom IComand class for one of my buttons. The button is placed in a page 'MyPage.xaml' but its custom ICommand class is placed in another class, not in the MyPage code behind. Then from XAML I want to bind the button with its custom command class and then I do: MyPage.xaml: <Page ...> <Page.CommandBindings> <CommandBinding Command="RemoveAllCommand" CanExecute="CanExecute" Executed="Execute" /> </Page.CommandBindings> <Page.InputBindings> <MouseBinding Command="RemoveAllCommand" MouseAction="LeftClick" /> </Page.InputBindings> <...> <Button x:Name="MyButton" Command="RemoveAllCommand" .../> <...> </Page> and the custom command button class: // Here I derive from MyPage class because I want to access some objects from // Execute method public class RemoveAllCommand : MyPage, ICommand { public void Execute(Object parameter) { <...> } public bool CanExecute(Object parameter) { <...> } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } } My problem is how to say MyPage.xaml that Execute and CanExecute methods for the button is in another class and not the code behind where is placed the button. How to say these methods are in RemoveAllCommand Class in XAML page. Also I want to fire this command when click mouse event is produced in the button so I do an input binding, is it correct? Thanks

    Read the article

  • WPF TextBox Interceping RoutedUICommands

    - by Joseph Sturtevant
    I am trying to get Undo/Redo keyboard shortcuts working in my WPF application (I have my own custom functionality implemented using the Command Pattern). It seems, however, that the TextBox control is intercepting my "Undo" RoutedUICommand. What is the simplest way to disable this so that I can catch Ctrl+Z at the root of my UI tree? I would like to avoid putting a ton of code/XAML into each TextBox in my application if possible. The following briefly demonstrates the problem: <Window x:Class="InputBindingSample.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:loc="clr-namespace:InputBindingSample" Title="Window1" Height="300" Width="300"> <Window.CommandBindings> <CommandBinding Command="loc:Window1.MyUndo" Executed="MyUndo_Executed" /> </Window.CommandBindings> <DockPanel LastChildFill="True"> <StackPanel> <Button Content="Ctrl+Z Works If Focus Is Here" /> <TextBox Text="Ctrl+Z Doesn't Work If Focus Is Here" /> </StackPanel> </DockPanel> </Window> using System.Windows; using System.Windows.Input; namespace InputBindingSample { public partial class Window1 { public static readonly RoutedUICommand MyUndo = new RoutedUICommand("MyUndo", "MyUndo", typeof(Window1), new InputGestureCollection(new[] { new KeyGesture(Key.Z, ModifierKeys.Control) })); public Window1() { InitializeComponent(); } private void MyUndo_Executed(object sender, ExecutedRoutedEventArgs e) { MessageBox.Show("MyUndo!"); } } }

    Read the article

  • Expression Blend doesn't recognize comand objects declared in code behind file

    - by Brian Ensink
    I have a WPF UserControl. The code behind file declares some RoutedUICommand objects which are referenced in the XAML. The application builds and runs just fine. However Expression Blend 3 cannot load the XAML in the designer and gives errors like this one: The member "ResetCameraComand" is not recognized or accessible. The class and the member are both public. Building and rebuilding the project in Blend and restarting Blend hasn't helped. Any ideas what the problem is? Here are fragments of my XAML ... <UserControl x:Class="CAP.Visual.CameraAndLightingControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:CAP.Visual;assembly=VisualApp" Height="100" Width="700"> <UserControl.CommandBindings> <CommandBinding Command="local:CameraAndLightingControl.ResetCameraCommand" Executed="ResetCamera_Executed" CanExecute="ResetCamera_CanExecute"/> </UserControl.CommandBindings> .... ... and the code behind C# namespace CAP.Visual { public partial class CameraAndLightingControl : UserControl { public readonly static RoutedUICommand ResetCameraCommand; static CameraAndLightingControl() { ResetCameraCommand = new RoutedUICommand("Reset Camera", "ResetCamera", typeof(CameraAndLightingControl)); }

    Read the article

  • Why can't I Bind a viewmodel property to a dependency property of a custom control

    - by Robert
    I want to use a color picker in my wpf application and I saw a nice looking one on this codeproject page. The control works fine until I want to connect the control to a viewmodel. I created a small test program with this viewmodel: public class ColorViewModel : ViewModelBase { public ColorViewModel() { LineColor = Brushes.Yellow; } SolidColorBrush _brushColor; public SolidColorBrush LineColor { get { return _brushColor; } set { _brushColor = value; RaisePropertyChanged(() => LineColor); } } } The test program has a textbox and the colorpicker controls: <StackPanel Orientation="Horizontal"> <TextBlock Text="Please Select a Color" FontWeight="Bold" Margin="10" Foreground="{Binding Path=LineColor, UpdateSourceTrigger=PropertyChanged}"/> <vw:ColorPickerControlView x:Name="ForeColorPicker" Margin="10" CurrentColor="{Binding Path=LineColor, UpdateSourceTrigger=PropertyChanged }"/> </StackPanel> In the loaded event of the window I set the viewmodel to the datacontext like this: DataContext = new ColorViewModel(); The problem is that I can't seem to bind the LineColor property of the viewmodel to the CurrentColor property of the ColorPickerControlView. The CurrentControl property of the ColorPickerControlView seems to be fine. The constructor looks like this: public ColorPickerControlView() { this.DataContext = this; InitializeComponent(); CommandBindings.Add(new CommandBinding(SelectColorCommand, SelectColorCommandExecute)); } In the constructor of the UserControl there is the line this.DataContext = this; I read that is is necessary to bind the dependency properties. Do I override this line when I set my viewmodel to the datacontext and is that why I can't bind to the CurrentColor property? Is there any workaround? Or did I make another mistake?

    Read the article

  • Setting CommandTarget to selected control in a TabControl

    - by Bart
    I have a WPF window with a few buttons and a tabcontrol having a tab for each 'document' the user is working on. The tabcontrol uses a DataTemplate to render the data in ItemSource of the tabcontrol. The question: If one of the buttons is clicked, the command should be executed on the control rendering the document in the active tab, but I've no idea what I should set CommandTarget to. I tried {Binding ElementName=nameOfControlInDataTemplate} but that obviously doesn't work. I tried to make my problem a bit more abstract with the following code (no ItemSource and Document objects, but the idea is still the same). <Button Command="ApplicationCommands.Save" CommandTarget="{Binding ElementName=nestedControl}">Save</Button> <TabControl x:Name="tabControl"> <TabControl.Items> <TabItem Header="Header1">Item 1</TabItem> <TabItem Header="Header2">Item 2</TabItem> <TabItem Header="Header3">Item 3</TabItem> </TabControl.Items> <TabControl.ContentTemplate> <DataTemplate> <CommandTest:NestedControl Name="nestedControl"/> </DataTemplate> </TabControl.ContentTemplate> </TabControl> I tested the code by replacing the complete tabcontrol with only one single NestedControl, and then the command button just works. To be complete, here is the code of NestedControl: <UserControl x:Class="CommandTest.NestedControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> <Label x:Name="label" Content="Not saved"/> </Grid> </UserControl> And code behind: public partial class NestedControl : UserControl { public NestedControl() { CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, CommandBinding_Executed)); InitializeComponent(); } private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { label.Content = "Saved"; } }

    Read the article

1 2  | Next Page >