Hi all,
Basic info: VS2010, .Net 4.0 WPF application.
I'm trying to write a dialog box that allows a user to edit a fairly simple configuration file, opened as an XMLDataProvider as an application-level resource. There are some basic settings, which I've bound to individual TextBoxes. Then there's a list of name-value pairs, which I've bound to columns in a datagrid.
I would like the dialog box to only update the resource when the user clicks OK. So I've set UpdateSourceTrigger=Explicit on all the TextBox bindings, and called UpdateSource() for each of the TextBoxes in the OK_click event handler. This works fine.
My problem is that for the life of me I can't stop the datagrid from updating its source prematurely (nor can I work out how I can access the relevant object to call UpdateSource() myself, but that's a separate question). I've tried with both DGTextColumns and DGTemplateColumns; same results both times. No matter how many Explicit update trigger settings I sprinkle around, the source is updated as soon as the DataGrid cells are edited.
This MSDN blogpost suggests that the DataGrid control is doing something weird internally with source updates - should I be looking to create a derived DataGrid so that I can override its behaviour? I tried suggestion 3 in the blogpost with no luck...
Basic info: VS2010, .Net 4.0 WPF application.
I'm trying to write a dialog box that allows a user to edit a fairly simple configuration file, opened as an XMLDataProvider as an application-level resource. There are some basic settings, which I've bound to individual TextBoxes. Then there's a list of name-value pairs, which I've bound to columns in a datagrid.
I would like the dialog box to only update the resource when the user clicks OK. So I've set UpdateSourceTrigger=Explicit on all the TextBox bindings, and called UpdateSource() for each of the TextBoxes in the OK_click event handler. This works fine.
My problem is that for the life of me I can't stop the datagrid from updating its source prematurely (nor can I work out how I can access the relevant object to call UpdateSource() myself, but that's a separate question). I've tried with both DGTextColumns and DGTemplateColumns; same results both times. No matter how many Explicit update trigger settings I sprinkle around, the source is updated as soon as the DataGrid cells are edited.
This MSDN blogpost suggests that the DataGrid control is doing something weird internally with source updates - should I be looking to create a derived DataGrid so that I can override its behaviour? I tried suggestion 3 in the blogpost with no luck...
Code:
<DataGrid
Name="DataGridExercises"
AutoGenerateColumns="False"
ItemsSource="{Binding Source={StaticResource testDefinition}}"
HeadersVisibility="Column">
<DataGrid.Columns>
<DataGridTextColumn Header="Exercise Name" Width="*"
Binding="{Binding XPath=@Name,
Mode=TwoWay, UpdateSourceTrigger=Explicit}"/>
<DataGridTextColumn Header="Time (s)"
Binding="{Binding XPath=@Time,
Mode=TwoWay, UpdateSourceTrigger=Explicit}"/>
</DataGrid.Columns>
</DataGrid>