Click here to Skip to main content
15,313,293 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Another real newbie question - wiring events to handlers not in the code-behind class Pin
Mycroft Holmes3-Feb-14 3:05
professionalMycroft Holmes3-Feb-14 3:05 
GeneralRe: Another real newbie question - wiring events to handlers not in the code-behind class Pin
_Maxxx_3-Feb-14 9:29
professional_Maxxx_3-Feb-14 9:29 
GeneralRe: Another real newbie question - wiring events to handlers not in the code-behind class Pin
Marc Clifton5-Feb-14 15:13
mvaMarc Clifton5-Feb-14 15:13 
GeneralRe: Another real newbie question - wiring events to handlers not in the code-behind class Pin
_Maxxx_5-Feb-14 15:26
professional_Maxxx_5-Feb-14 15:26 
QuestionHow do I wire Command to functions not in the view? Pin
Marc Clifton2-Feb-14 10:14
mvaMarc Clifton2-Feb-14 10:14 
QuestionHow to bind a dataset to a WPF richtextbox? Pin
fsunole0329-Jan-14 10:43
Memberfsunole0329-Jan-14 10:43 
AnswerRe: How to bind a dataset to a WPF richtextbox? Pin
Wayne Gaylard30-Jan-14 1:07
professionalWayne Gaylard30-Jan-14 1:07 
QuestionHandling RowEditEnding in a DataGrid according to MVVM pattern Pin
Piotr Z27-Jan-14 23:43
MemberPiotr Z27-Jan-14 23:43 
Hi,

I'm trying to handle the RowEditEnding Event on my dataGrid that contains data from LINQ to SQL context. Datagrid contains following items:

XML
<DataGrid RowEditEnding="dtgMyList_RowEditEnding" ItemsSource="{Binding ListAllItems}" AutoGenerateColumns="False" Grid.Row="1" x:Name="dtgMyList" Margin="2,2,2,2"  VerticalAlignment="Top">
    <DataGrid.Columns>
        <DataGridTextColumn IsReadOnly="True" Binding="{Binding ArtikelID, NotifyOnSourceUpdated=True}"  Header="ID"/>
        <DataGridTextColumn IsReadOnly="False" Binding="{Binding ArtikelBeschreibung, UpdateSourceTrigger=LostFocus}" Header="Beschreibung"/>
        <DataGridTextColumn IsReadOnly="False" Binding="{Binding Gesperrt,UpdateSourceTrigger=LostFocus}" Header="Gesperrt"/>
    </DataGrid.Columns>
</DataGrid>


So far I'm able to implement the Event handling in code behind, but this is against MVVM Guidelines.

Current implementation:

In View

public delegate void RowEditIntercept(object sender, DataGridRowEditEndingEventArgs e);


public event RowEditIntercept MyRowChanged;


C#
private void dtgMyList_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
    MyDataDataSerice ser = new MyDataDataSerice(this);
    MyRowChanged(sender, e);

}



In MyDataService class

private MainWindow _window;

public MyDataDataSerice(MainWindow window)
{
    _window = window;
    this._window.MyRowChanged += new RowEditIntercept(DoEditMyRows);
}


internal void DoEditMyRows(object sender, DataGridRowEditEndingEventArgs e)
{
    if (e.EditAction == DataGridEditAction.Commit)
    {
        linqMyDataDataContext context = new linqMyDataDataContext();
        tblStammDaten stamm = e.Row.DataContext as tblStammDaten;

        var matchedData = (from em in context.GetTable<tblStammDaten>()
                           where em.ArtikelID == stamm.ArtikelID
                           select em).SingleOrDefault();

        matchedData.ArtikelBeschreibung = stamm.ArtikelBeschreibung;
        matchedData.Gesperrt = stamm.Gesperrt;
        context.SubmitChanges();

    }
}


If I understand correctly, I need to find a way to intercept the Event arguments (object sender, DataGridRowEditEndingEventArgs e).

How can I do this in my ViewModel withough writing code in the View?

Thanks in advance!
Piotr
AnswerRe: Handling RowEditEnding in a DataGrid according to MVVM pattern Pin
Pete O'Hanlon28-Jan-14 0:29
mvaPete O'Hanlon28-Jan-14 0:29 
GeneralRe: Handling RowEditEnding in a DataGrid according to MVVM pattern Pin
Piotr Z28-Jan-14 0:51
MemberPiotr Z28-Jan-14 0:51 
GeneralRe: Handling RowEditEnding in a DataGrid according to MVVM pattern Pin
Pete O'Hanlon28-Jan-14 1:10
mvaPete O'Hanlon28-Jan-14 1:10 
AnswerRe: Handling RowEditEnding in a DataGrid according to MVVM pattern Pin
_Maxxx_2-Feb-14 19:36
professional_Maxxx_2-Feb-14 19:36 
QuestionProblems updating datagrid from collection Pin
abollmeyer23-Jan-14 10:55
Memberabollmeyer23-Jan-14 10:55 
AnswerRe: Problems updating datagrid from collection Pin
Mycroft Holmes23-Jan-14 12:04
professionalMycroft Holmes23-Jan-14 12:04 
QuestionBinding property from XML file data Pin
abollmeyer21-Jan-14 9:18
Memberabollmeyer21-Jan-14 9:18 
AnswerRe: Binding property from XML file data Pin
abollmeyer21-Jan-14 14:44
Memberabollmeyer21-Jan-14 14:44 
QuestionCombobox / Textblock field Pin
eddieangel21-Jan-14 6:24
Membereddieangel21-Jan-14 6:24 
AnswerRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 7:52
professionalJason Gleim21-Jan-14 7:52 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 8:07
Membereddieangel21-Jan-14 8:07 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 8:48
professionalJason Gleim21-Jan-14 8:48 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 9:14
Membereddieangel21-Jan-14 9:14 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 9:42
professionalJason Gleim21-Jan-14 9:42 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 10:12
Membereddieangel21-Jan-14 10:12 
GeneralRe: Combobox / Textblock field Pin
Jason Gleim21-Jan-14 10:25
professionalJason Gleim21-Jan-14 10:25 
GeneralRe: Combobox / Textblock field Pin
eddieangel21-Jan-14 11:29
Membereddieangel21-Jan-14 11:29 

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.