or
<
Window.Resources
>
<
Style
x:Key
=
"itemStyle"
TargetType
=
"telerik:RadTreeViewItem"
>
<
Setter
Property
=
"IsSelected"
Value
=
"{Binding Path=Select, Mode=TwoWay}"
/>
<
Setter
Property
=
"IsExpanded"
Value
=
"{Binding Path=Expand, Mode=TwoWay}"
/>
<
Setter
Property
=
"IsInEditMode"
Value
=
"{Binding Path=EditMode, Mode=TwoWay}"
/>
</
Style
>
</
Window.Resources
>
<
DockPanel
>
<
StackPanel
Orientation
=
"Vertical"
DockPanel.Dock
=
"Bottom"
>
<
Button
Command
=
"{Binding AddCommand}"
>Add Person</
Button
>
<
Button
Command
=
"{Binding DeleteCommand}"
>Delete current</
Button
>
</
StackPanel
>
<
telerik:RadTreeView
IsEditable
=
"True"
ItemsSource
=
"{Binding Persons}"
ItemContainerStyle
=
"{StaticResource itemStyle}"
SelectedItem
=
"{Binding Path=Current, Mode=TwoWay}"
>
<
telerik:RadTreeView.ItemTemplate
>
<
HierarchicalDataTemplate
ItemsSource
=
"{Binding Childs}"
>
<
TextBlock
Text
=
"{Binding Name}"
/>
</
HierarchicalDataTemplate
>
</
telerik:RadTreeView.ItemTemplate
>
</
telerik:RadTreeView
>
</
DockPanel
>
Persons.Add(
new
PersonViewModel(
new
Model.Person(
"New person"
,
new
string
[]{})) { Select=
true
, EditMode=
true
});
if
(Current !=
null
)
{
if
(Current.Parent !=
null
) Current.Parent.Childs.Remove(Current);
else
person.Remove(Current);
// Not the role to viewmodel to select another element
}
GridSelectedZipCodes.ItemsSource = ZipGeoCodeService.GetForZipPart((string)item.Header, (float)_selectedDealer.Latitude, (float)_selectedDealer.Longitude, (float)_selectedDealer.MaxDistance);
static public List<
ZipGeoCode
> GetForZipPart(string zippart, float latitude, float longitude, float distance)
private void SelectZipCodes()
{
IsLoading = true;
foreach (ZipGeoCode _item in GridSelectedZipCodes.Items)
{
if (_dealerZipCodes.Find(delegate(ZipGeoCode zgc) {return zgc.ID == _item.ID; }) != null)
{
GridSelectedZipCodes.SelectedItems.Add(_item);
}
}
IsLoading = false;
}
SelectionChangeEventArgs
would be great.private
void
GridSelectedZipCodes_SelectionChanged(
object
sender, SelectionChangeEventArgs e)
{
if
(!(IsLoading))
{
//remove all items
foreach
(ZipGeoCode _item
in
GridSelectedZipCodes.Items)
{
if
(_dealerZipCodes.Find(
delegate
(ZipGeoCode zgc) {
return
zgc.ID == _item.ID; }) !=
null
)
{
_dealerZipCodes.Remove(_item);
}
}
foreach
(ZipGeoCode _item
in
GridSelectedZipCodes.SelectedItems)
{
_dealerZipCodes.Add(_item);
}
}
}
#region Deklarationen
private
ObservableCollection<RWF_GUI_TransferItems> _Items;
/// <summary>
/// Enthält alle Elemente die in dem GridView dargestellt werden.
/// </summary>
public
ObservableCollection<RWF_GUI_TransferItems> Items
{
get
{
return
_Items; }
set
{
_Items = value;
this
.ValueChanged(
"Items"
);
}
}
private
ICollectionView _ItemsView;
/// <summary>
/// View zur Überwachtung des aktuellen Grid-Items
/// </summary>
public
ICollectionView ItemsView
{
get
{
return
_ItemsView; }
set
{
_ItemsView = value;
this
.ValueChanged(
"ItemsView"
);
}
}
private
RWF_GUI_TransferItems _AktuelleGridAuswahl;
/// <summary>
/// Aktuelle Gridzeile
/// </summary>
public
RWF_GUI_TransferItems AktuelleGridAuswahl
{
get
{
return
_AktuelleGridAuswahl; }
set
{
_AktuelleGridAuswahl = value;
this
.ValueChanged(
"AktuelleGridAuswahl"
);
}
}
public
MainViewModel()
{
this
.Items =
new
ObservableCollection<RWF_GUI_TransferItems>();
this
.ItemsView = CollectionViewSource.GetDefaultView(
this
.Items);
this
.ItemsView.CurrentChanged +=
new
EventHandler(OnCurrentItemChanged);
}
void
OnCurrentItemChanged(
object
sender, EventArgs e)
{
this
.AktuelleGridAuswahl = (RWF_GUI_TransferItems)
this
.ItemsView.CurrentItem;
}
<
telerik:RadGridView
ItemsSource
=
"{Binding ItemsView}"
RowHeight
=
"25"
CanUserFreezeColumns
=
"False"
AutoGenerateColumns
=
"False"
ShowColumnFooters
=
"true"
x:Name
=
"GridViewMain"
IsSynchronizedWithCurrentItem
=
"True"
IsEnabled
=
"{Binding AtWork, Converter={StaticResource NegateBoolConverter}}"
>
OnCurrentItemChanged
-Event is only being raised on startup (this.ItemsView.CurrentItem is null at this moment).