Hi. I have another trouble with grid update (SelectedItem)
Briefly...
I'm using:
- Silverlight
- MVVM (library MVVM light)
- RIA (DomainDataSource)
- RadGridView (2010.2 812 (Aug 12, 2010))
Please, look at the picture named map_of_actions.png (see attachments).
Main ViewModel (Which name is HomeViewModel) has 3 ViewModel. They are all linked.
1. ACTION 1: When I click on Master1 treeview (DepartmentTreeViewModel) the Detail1 (GridView) is reloaded details records (at map it ACTION 2).
2.ACTION 3: When I click on Master2 gridview (StaffViewModel) the Detail2 (GridView) is reloaded details records for master2 (at map see ACTION 4).
3. And now the issue: how I can make GridView (Master2) update your selectedItem for Deteil2. When I click Master1 DETAIL2 must update too! But Master2 SelectedItem not updated.
I was try many events on gridview, but they are not fired when DomainDataSource event LoadedData completed And also I was try the DomainDataSource event LoadedData, but I can't find solution HOW can gridview make your SelectedItem updated (for example, just set first loaded item selected).
Same piece of code
StaffView.xaml:
namespaces
xmlns:qph="clr-namespace:BusinessApplication.Helpers"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:clb="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"
grid and domaindatasource
<
sdk:RadGridView
HorizontalAlignment
=
"Stretch"
Width
=
"auto"
x:Name
=
"grid"
PropertyChanged
=
"grid_PropertyChanged"
SelectionMode
=
"Single"
IsSynchronizedWithCurrentItem
=
"True"
ItemsSource
=
"{Binding ElementName=DataSource, Path=Data}"
AutoGenerateColumns
=
"False"
>
<
i:Interaction.Triggers
>
<
i:EventTrigger
EventName
=
"SelectionChanged"
>
<
clb:EventToCommand
Command
=
"{Binding Path=SelectionChangedCommand}"
CommandParameter
=
"{Binding ElementName=grid}"
/>
</
i:EventTrigger
>
</
i:Interaction.Triggers
>
<
sdk:RadGridView.Columns
>
<
sdk:GridViewDataColumn
Header
=
"Должность"
DataMemberBinding
=
"{Binding Path=JobTitle.Name}"
/>
<
sdk:GridViewDataColumn
Header
=
"DepartmentTree"
DataMemberBinding
=
"{Binding Path=DepartmentTree.Name}"
/>
<
sdk:GridViewDataColumn
Header
=
"Salary"
DataMemberBinding
=
"{Binding Path=Salary}"
/>
</
sdk:RadGridView.Columns
>
</
sdk:RadGridView
>
<
riaControls:DomainDataSource
AutoLoad
=
"True"
Height
=
"0"
LoadSize
=
"60"
LoadDelay
=
"00:00:01"
Name
=
"DataSource"
QueryName
=
"{Binding Path=DetailInfo.CurrentQueryName}"
DomainContext
=
"{Binding Path=Data.BridgeContext}"
Width
=
"0"
qph:QueryParametersHelper.DetailInfo
=
"{Binding Path=DetailInfo}"
FilterOperator
=
"And"
>
</
riaControls:DomainDataSource
>
Class QueryParametersHelper
#region DetailInfo
/// <summary>
/// DetailInfo Attached Dependency Property
/// </summary>
public
static
readonly DependencyProperty DetailInfoProperty =
DependencyProperty.RegisterAttached(
"DetailInfo"
, typeof(DetailDefinition), typeof(DomainDataSource),
new PropertyMetadata(null, OnDetailInfoChanged));
/// <summary>
/// Gets the DetailInfo property. This dependency property
/// indicates ....
/// </summary>
public
static
DetailDefinition GetDetailInfo(DependencyObject d)
{
return (DetailDefinition)d.GetValue(DetailInfoProperty);
}
/// <summary>
/// Sets the DetailInfo property. This dependency property
/// indicates ....
/// </summary>
public
static
void SetDetailInfo(DependencyObject d, DetailDefinition value)
{
d.SetValue(DetailInfoProperty, value);
}
/// <summary>
/// Handles changes to the DetailInfo property.
/// </summary>
private
static
void OnDetailInfoChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
DomainDataSource dds = (DomainDataSource)d;
if (dds != null)
{
DetailDefinition detail = (DetailDefinition)e.NewValue;
detail.DomainDataSource = dds;
}
}
#endregion
class StaffViewModel command SelectionChangedCommand
#region команда SelectionChangedCommand
/// <summary>
/// Calabonga: Команда SelectionChangedCommand
/// </summary>
public
RelayCommand<
object
> SelectionChangedCommand
{
get
{
return
new
RelayCommand<
object
>((e) =>
this
.SelectionChangedCommandExecute(e),
(e) =>
this
.CanExecuteSelectionChanged(e));
}
}
/// <summary>
/// Calabonga: Процедура выполняет команды SelectionChangedCommand
/// </summary>
private
void
SelectionChangedCommandExecute(
object
e)
{
// выполнение команды SelectionChanged
object
currentItem = ((RadGridView)e).CurrentItem;
SelectedId = ((Staff)currentItem).Id;
}
/// <summary>
/// Calabonga: Свойство проверки возможности выполнения команды SelectionChangedCommand()
/// </summary>
private
bool
CanExecuteSelectionChanged(
object
e)
{
// разрешен ли запуск команды
return
e !=
null
;
}
#endregion // end команда SelectionChangedCommand
And the last code of class StaffViewModel property SelectedId:
#region SelectedId
private
int
selectedId = -1;
public
int
SelectedId
{
get
{
return
selectedId; }
set
{
if
(selectedId == value)
return
;
selectedId = value;
RaisePropertyChanged(
"SelectedId"
);
Messenger.Default.Send(selectedId,
"Staff"
);
}
}
#endregion
P.S.: PersonViewModel class has the same properties and methods.
Please help me. GridView with Persons entityties must be updated too when I change selection on TreeView (MASTER1)!!!