Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1770
XamRibbon ButtonTool vs WPF Button - different results when rejecting changes in DataTable
posted

have a XamDataGrid with a DataTable as a source:

<dataPresenter:XamDataGrid Grid.Row="1" DataSource="{Binding TestData}" GroupByAreaLocation="None"/>

I'm using MVVM Light to handle commands. In my view model I have:

public class MainViewModel: ViewModelBase { 
public RelayCommand OnCancel { get; set; } 
private DataTable _testData; 
public DataTable TestData { get { return _testData; } 
set { Set(() => TestData, ref _testData, value); } } 
public MainViewModel() { OnCancel = new RelayCommand(Cancel); } 
private void Cancel() { TestData.RejectChanges(); } }

To handle the commands I want to use the XamRibbon:


<igWPF:XamRibbon >
<igWPF:XamRibbon.Tabs>
<igWPF:RibbonTabItem Header="Logs">
<igWPF:RibbonGroup Caption="Data Controls">
<igWPF:ToolHorizontalWrapPanel>
<igWPF:ButtonTool Caption="Get Data" Command="{Binding OnGetData}" />
<igWPF:ButtonTool Caption="Cancel" Command="{Binding OnCancel}" />
</igWPF:ToolHorizontalWrapPanel>
</igWPF:RibbonGroup>
</igWPF:RibbonTabItem>
</igWPF:XamRibbon.Tabs>
</igWPF:XamRibbon>

<!--<StackPanel Orientation="Horizontal"> 
<Button Content="Get Data" Command="{Binding OnGetData}" Margin="0,0,20,0" Height="40"/> 
<Button Content="Cancel" Command="{Binding OnCancel}" Height="40"/> 
</StackPanel>-->

I'm getting different behavior when using the ButtonTool in XamRibbon vs just the Button. What I want is to reject any changes made in the XamDataGrid. When I use the Button, the changes are rejected in the DataTable and the XamDataGrid updates accordingly. When I change the code so the ButtonTool executes the Cancel method this does not happen. The behavior seems sporadic. The XamDataGrid is not properly updated even though I can see changes have been reject in the DataTable. Why would this be happening?

I've attached a sample project to illustrate my issue. 

1. Click "Get Data"

2. Make some random numerical entry in the Value column of the first row.

3. WITHOUT clicking outside of the cell the changes were made in, click the "Cancel" button.

Notice that the changes are rejected in the DataTable but not updated in the XamDataGrid. This is contrary to when simply changing the buttons from the XamRibbon to plain WPF Button control. Pressing "Cancel" rejects the changes and the XamDataGrid is updated.

CellIssues.zip