Click here to Skip to main content
15,887,027 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF - Why? Pin
SteveHolle6-Nov-14 4:22
SteveHolle6-Nov-14 4:22 
GeneralRe: WPF - Why? Pin
Mycroft Holmes6-Nov-14 11:36
professionalMycroft Holmes6-Nov-14 11:36 
GeneralRe: WPF - Why? Pin
Gary R. Wheeler8-Nov-14 3:12
Gary R. Wheeler8-Nov-14 3:12 
GeneralRe: WPF - Why? Pin
Pete O'Hanlon11-Nov-14 20:46
mvePete O'Hanlon11-Nov-14 20:46 
QuestionProblem to synchronise two DataContext bound ComboBoxes Pin
Tom Rahav10-Oct-14 18:25
Tom Rahav10-Oct-14 18:25 
AnswerRe: Problem to synchronise two DataContext bound ComboBoxes Pin
Gerry Schmitz13-Oct-14 11:39
mveGerry Schmitz13-Oct-14 11:39 
GeneralRe: Problem to synchronise two DataContext bound ComboBoxes Pin
Tom Rahav13-Oct-14 14:39
Tom Rahav13-Oct-14 14:39 
QuestionDataGrid won't detect CTRL + C Pin
Mc_Topaz9-Oct-14 3:17
Mc_Topaz9-Oct-14 3:17 
I have a WPF applicaiton where the MainWindow class have <Window.CommandBindings> and <Window.InputBindings> so I can use CTRL + X, CTRL + C and CTRL + V commands.

The MainWindow contains a DataGrid where I want to select a row and copy the data in the row with the CTRL + C command. When a row is selected in the DataGrid the CTRL + C command stops working. CTRL + X and CTRL + V are still detected.

I have managed to reproduce this problem. Just copy and paste the code below, it should compile and run on the go.

Then do the following:
Press either CTRL + X, CTRL + C or CTRL + V you will get a popup window saying what command was activated.
Select a row in the DataGrid and then run CTRL + C. Nothing will happen.

MainWindow.XAML code
XML
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <!-- Commands for hot keys -->
    <Window.CommandBindings>

        <!-- Source -->
        <!-- http://stackoverflow.com/questions/4682915/defining-menuitem-shortcuts -->

        <CommandBinding Command="Cut" Executed="btnCut_Click" />
        <CommandBinding Command="Copy" Executed="btnCopy_Click" />
        <CommandBinding Command="Paste" Executed="btnPaste_Click" />

    </Window.CommandBindings>

    <!-- Hot keys -->
    <Window.InputBindings>
        <KeyBinding Key="X" Modifiers="Control" Command="Cut" />
        <KeyBinding Key="C" Modifiers="Control" Command="Copy" />
        <KeyBinding Key="V" Modifiers="Control" Command="Paste" />
    </Window.InputBindings>

    <Grid>
        <DataGrid Name="dgPersons" HorizontalScrollBarVisibility="Auto" AutoGenerateColumns="False" IsReadOnly="True" SelectionMode="Extended" GridLinesVisibility="None" Background="White" Margin="75,59,35,104">

            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0" />
                    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                </Style>
            </DataGrid.CellStyle>

            <DataGrid.Columns>
                
                <!-- Name -->
                <DataGridTextColumn Header="Name" Width="100" Binding="{Binding Name, Mode=OneTime}" />
                
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>


MainWindow.cs code
C#
using System;
//using System.Collections.Generic;
using System.Collections.ObjectModel;
//using System.Linq;
//using System.Text;
using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Data;
//using System.Windows.Documents;
using System.Windows.Input;
//using System.Windows.Media;
//using System.Windows.Media.Imaging;
//using System.Windows.Navigation;
//using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        ObservableCollection<Person> persons = new ObservableCollection<Person>();

        public MainWindow()
        {
            InitializeComponent();

            Person person1 = new Person("Person1");
            Person person2 = new Person("Person2");
            Person person3 = new Person("Person3");

            persons.Add(person1);
            persons.Add(person2);
            persons.Add(person3);

            dgPersons.ItemsSource = persons;

        }

        private void btnCut_Click(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("CUT command activated");
        }

        private void btnCopy_Click(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("COPY command activated");
        }

        private void btnPaste_Click(object sender, ExecutedRoutedEventArgs e)
        {
            MessageBox.Show("PASTE command activated");
        }
    }

    public class Person
    {
        string name;

        public Person(string name)
        {
            this.name = name;
        }

        public string Name
        {
            get { return name; }
        }
    }
}


How do I get CTRL + C wrking when a row is selected in the DataGrid?
AnswerRe: DataGrid won't detect CTRL + C Pin
Vincent Beek9-Oct-14 15:23
Vincent Beek9-Oct-14 15:23 
QuestionRe: DataGrid won't detect CTRL + C Pin
Mc_Topaz9-Oct-14 20:08
Mc_Topaz9-Oct-14 20:08 
AnswerRe: DataGrid won't detect CTRL + C Pin
Vincent Beek9-Oct-14 20:25
Vincent Beek9-Oct-14 20:25 
AnswerRe: DataGrid won't detect CTRL + C Pin
Hi I am Kevin29-Oct-14 6:05
Hi I am Kevin29-Oct-14 6:05 
QuestionViewBox Button alignment Pin
Member 102727486-Oct-14 10:00
Member 102727486-Oct-14 10:00 
AnswerRe: ViewBox Button alignment Pin
Mycroft Holmes6-Oct-14 14:21
professionalMycroft Holmes6-Oct-14 14:21 
QuestionDisplaying Validation Pin
cjb1102-Oct-14 21:49
cjb1102-Oct-14 21:49 
AnswerRe: Displaying Validation Pin
cjb1102-Oct-14 23:05
cjb1102-Oct-14 23:05 
QuestionReport Not Showing All Data Pin
Kevin Marois29-Sep-14 10:20
professionalKevin Marois29-Sep-14 10:20 
QuestionWPF Reporting Question Pin
Kevin Marois23-Sep-14 7:07
professionalKevin Marois23-Sep-14 7:07 
AnswerRe: WPF Reporting Question Pin
Bernhard Hiller23-Sep-14 21:56
Bernhard Hiller23-Sep-14 21:56 
GeneralRe: WPF Reporting Question Pin
Kevin Marois24-Sep-14 16:00
professionalKevin Marois24-Sep-14 16:00 
QuestionForm with ComboBoxes bound to the same source. Pin
cjb11016-Sep-14 2:45
cjb11016-Sep-14 2:45 
AnswerRe: Form with ComboBoxes bound to the same source. Pin
Pete O'Hanlon16-Sep-14 3:16
mvePete O'Hanlon16-Sep-14 3:16 
GeneralRe: Form with ComboBoxes bound to the same source. Pin
cjb11016-Sep-14 3:37
cjb11016-Sep-14 3:37 
GeneralRe: Form with ComboBoxes bound to the same source. Pin
Pete O'Hanlon16-Sep-14 6:25
mvePete O'Hanlon16-Sep-14 6:25 
GeneralRe: Form with ComboBoxes bound to the same source. Pin
cjb11017-Sep-14 22:05
cjb11017-Sep-14 22:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.