Hello. Just on DialogResult, I'm not wrong! I use System.Windows.Forms.FolderBrowserDialog instance in my WPF MVVM application. Please see the following code from the View Model:
. . . . . . . .
using
System.Windows.Forms;
. . . . . . . .
FolderBrowserDialog dialog =
new
FolderBrowserDialog();
DialogResult res = dialog.ShowDialog();
if
(res == DialogResult.OK)
{
this
.PathToExcelExportRepository =
string
.Copy(dialog.SelectedPath);
this
.IsTurnOffExportToExcelSelected =
false
;
this
.IsTurnOnExportToExcelSelected =
true
;
. . . . . . . . .
}
Where IsTurnOffExportToExcelSelected is:
public
bool
IsTurnOffExportToExcelSelected
{
get
{
return
this
._isTurnOffExportToExcelSelected; }
set
{
this
.SetProperty(
ref
this
._isTurnOffExportToExcelSelected, value); }
}
and IsTurnOnExportToExcelSelected is:
public
bool
IsTurnOnExportToExcelSelected
{
get
{
return
this
._isTurnOnExportToExcelSelected; }
set
{
this
.SetProperty(
ref
this
._isTurnOnExportToExcelSelected, value); }
}
Each one of these properties is binding source fore menu item in the View:
<telerik:RadContextMenu.ContextMenu>
<telerik:RadContextMenu>
<telerik:RadMenuItem Header=
"Turn on export to MS Excel"
IsCheckable=
"True"
IsChecked=
"{Binding IsTurnOnExportToExcelSelected, Mode=TwoWay}"
Command=
"{Binding TurnOnExportToExcelCommand}"
/>
<telerik:RadMenuItem Header=
"Turn off export to MS Excel"
IsCheckable=
"True"
IsChecked=
"{Binding IsTurnOffExportToExcelSelected, Mode=TwoWay}"
Command=
"{Binding TurnOffExportToExcelCommand}"
/>
</telerik:RadContextMenu>
</telerik:RadContextMenu.ContextMenu>
here the source code of TurnOnExportToExcelCommand. It turns on export to CSV-file of the values of real-time chart data-points:
// This line is in the View Model constructor.
this
.TurnOnExportToExcelCommand =
new
DelegateCommand(
this
.turnOnExportToExcel);
// This is the command definition in the View Model.
public
DelegateCommand TurnOnExportToExcelCommand {
get
;
private
set
; }
private
void
turnOnExportToExcel()
{
FolderBrowserDialog dialog =
new
FolderBrowserDialog();
DialogResult res = dialog.ShowDialog();
if
(res == DialogResult.OK)
{
this
.PathToExcelExportRepository =
string
.Copy(dialog.SelectedPath);
this
.IsTurnOffExportToExcelSelected =
false
;
this
.IsTurnOnExportToExcelSelected =
true
;
// Define for which chart (absolute or relative) export to CSV-file is turned on.
if
(
this
.IsAbsoluteSplineChartSelected ||
this
.IsAbsoluteBarChartSelected)
{
// Export of absolute chart data-point to CSV-file:
Interlocked.CompareExchange(
ref
this
._isAbsoluteChartDataBeingExported, 1, 0);
Task.Factory.StartNew(
this
.peekAbsoluteDataForExportToCsv, TaskCreationOptions.LongRunning);
Task.Factory.StartNew(
this
.exportToCsvAbsoluteChartPoints, TaskCreationOptions.LongRunning);
// Export absolute chart data-point values is turned on.
GlobalStaticMembers.ChartsExportToExcelStatus[0] =
true
;
}
else
if
(
this
.IsComparativeSplineChartSelected ||
this
.IsComparativeBarChartSelected)
{
// Export of relative chart data-point to CSV-file:
Interlocked.CompareExchange(
ref
this
._isComparativeChartDataBeingExported, 1, 0);
Task.Factory.StartNew(
this
.peekComparativeDataForExportToCsv, TaskCreationOptions.LongRunning);
Task.Factory.StartNew(
this
.exportToCsvComparativeChartPoints, TaskCreationOptions.LongRunning);
// Export relative chart data-point values is turned on.
GlobalStaticMembers.ChartsExportToExcelStatus[1] =
true
;
}
}
}
The condition of if-statement above is satisfied if DialogResult is DialogResult.OK. I verify it to set breakpoint in debugger. But if I click 'Cancel' button in the dialog then the debugger doesn't not show next steps but IsChecked property of IsTurnOnExportToExcelSelected menu item is set to true (the status of IsChecked property of TurnOffExportToMSExcel menu item is not changed). Why is TurnOnExportToMSExcel boolean property set to true if DialogResult is Cancel?