This question is locked. New answers and comments are not allowed.
Hi Telerik Team
In our project, we have a search (wcf service) where the user can export the result from this search. The Export of this result is handled with a RadButton and Command. (Export is only possible if a result exist!)
During the search, we display a BusyIndicator. When the search is finished and no results were found, the Export Button is still enabled, although the CanExecute of the Export Command is false!
Sample:
First, the two Buttons are disabled (because the Search-Result is null).
When you search for 'test', the Buttons becomes enabled (because 3 Results were found).
Now, when you search for 'testx', only the Button outside of the BusyIndicator becomes disabled. (Search-Result is null). The Button inside the BusyIndicator still is enabled!
Sample code:
ViewModel (DataContext of UserControl)
Thank you.
In our project, we have a search (wcf service) where the user can export the result from this search. The Export of this result is handled with a RadButton and Command. (Export is only possible if a result exist!)
During the search, we display a BusyIndicator. When the search is finished and no results were found, the Export Button is still enabled, although the CanExecute of the Export Command is false!
Sample:
First, the two Buttons are disabled (because the Search-Result is null).
When you search for 'test', the Buttons becomes enabled (because 3 Results were found).
Now, when you search for 'testx', only the Button outside of the BusyIndicator becomes disabled. (Search-Result is null). The Button inside the BusyIndicator still is enabled!
Sample code:
<
UserControl
x:Class
=
"SilverlightApplication3.BusyCommandTest"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignHeight
=
"500"
d:DesignWidth
=
"500"
>
<
telerik:RadDockPanel
>
<
telerik:RadButton
telerik:RadDockPanel.Dock
=
"Top"
Content
=
"Command (outside of RadBusyIndicator)"
Command
=
"{Binding ExportResultCommand}"
Margin
=
"30,30,30,10"
/>
<
telerik:RadBusyIndicator
IsIndeterminate
=
"True"
IsBusy
=
"{Binding IsBusy}"
BusyContent
=
"Going on..."
>
<
telerik:RadDockPanel
>
<
telerik:RadButton
telerik:RadDockPanel.Dock
=
"Top"
Content
=
"Command (inside of RadBusyIndicator)"
Command
=
"{Binding ExportResultCommand}"
Margin
=
"30,0,30,30"
/>
<
StackPanel
Orientation
=
"Horizontal"
telerik:RadDockPanel.Dock
=
"Top"
Margin
=
"30"
>
<
TextBox
Text
=
"{Binding SearchTerm, Mode=TwoWay}"
Width
=
"300"
/>
<
telerik:RadButton
Content
=
"Search"
Command
=
"{Binding SearchCommand}"
/>
<
telerik:RadButton
Content
=
"InvalidateCanExecute"
Command
=
"{Binding InvalidateCommand}"
/>
</
StackPanel
>
<
telerik:RadGridView
ItemsSource
=
"{Binding ResultList}"
Margin
=
"30"
/>
</
telerik:RadDockPanel
>
</
telerik:RadBusyIndicator
>
</
telerik:RadDockPanel
>
</
UserControl
>
ViewModel (DataContext of UserControl)
using
System.Collections.ObjectModel;
using
System.ComponentModel;
using
System.Threading;
using
System.Windows.Input;
using
Telerik.Windows.Controls;
namespace
SilverlightApplication3
{
public
class
BusyCommandViewModel : ViewModelBase
{
public
BusyCommandViewModel()
{
this
.PropertyChanged +=
new
System.ComponentModel.PropertyChangedEventHandler(BusyCommandViewModel_PropertyChanged);
}
void
BusyCommandViewModel_PropertyChanged(
object
sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if
(e.PropertyName ==
"ResultList"
)
{
ExportResultCommand.InvalidateCanExecute();
}
}
private
bool
isBusy;
public
bool
IsBusy
{
get
{
return
isBusy; }
set
{
isBusy = value;
this
.OnPropertyChanged(
"IsBusy"
);
}
}
private
string
searchTerm;
public
string
SearchTerm
{
get
{
return
searchTerm; }
set
{
searchTerm = value;
this
.OnPropertyChanged(
"SearchTerm"
);
}
}
private
ICommand searchCommand;
public
ICommand SearchCommand
{
get
{
if
(searchCommand ==
null
)
{
searchCommand =
new
DelegateCommand(
this
.DoSearch);
}
return
searchCommand;
}
}
private
void
DoSearch(
object
param)
{
this
.IsBusy =
true
;
// Backgroundworker to Simulate WCF Service Search
BackgroundWorker worker =
new
BackgroundWorker();
worker.DoWork += (sender, e) =>
{
Thread.SpinWait(100000000);
};
worker.RunWorkerCompleted +=
new
RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
}
void
worker_RunWorkerCompleted(
object
sender, RunWorkerCompletedEventArgs e)
{
if
(
this
.SearchTerm ==
"test"
)
{
ObservableCollection<TestObject> tempList =
new
ObservableCollection<TestObject>();
tempList.Add(
new
TestObject(
"Entry1.1"
,
"Entry1.2"
));
tempList.Add(
new
TestObject(
"Entry2.1"
,
"Entry2.2"
));
tempList.Add(
new
TestObject(
"Entry3.1"
,
"Entry3.2"
));
this
.ResultList = tempList;
}
else
{
this
.ResultList =
null
;
}
this
.IsBusy =
false
;
}
private
DelegateCommand exportResultCommand;
public
DelegateCommand ExportResultCommand
{
get
{
if
(exportResultCommand ==
null
)
{
exportResultCommand =
new
DelegateCommand(
this
.DoExportResult,
this
.CanExportResult);
}
return
exportResultCommand;
}
}
private
bool
CanExportResult(
object
p)
{
bool
canExport =
this
.ResultList !=
null
&&
this
.ResultList.Count > 0;
return
canExport;
}
private
void
DoExportResult(
object
p)
{
// Action to Export
}
private
ICommand invalidateCommand;
public
ICommand InvalidateCommand
{
get
{
if
(invalidateCommand ==
null
)
{
invalidateCommand =
new
DelegateCommand(
this
.DoInvalidate);
}
return
invalidateCommand;
}
}
private
void
DoInvalidate(
object
param)
{
ExportResultCommand.InvalidateCanExecute();
}
private
ObservableCollection<TestObject> resultList;
public
ObservableCollection<TestObject> ResultList
{
get
{
return
resultList; }
set
{
resultList = value;
this
.OnPropertyChanged(
"ResultList"
);
}
}
}
public
class
TestObject
{
public
TestObject(
string
column1,
string
column2)
{
this
.Column1 = column1;
this
.Column2 = column2;
}
public
string
Column1 {
get
;
set
; }
public
string
Column2 {
get
;
set
; }
}
}
Thank you.