I have a RadTreeView bound in an MVVM style application. If a selection does not contain Details I need to disable the ability to click on that node and keep the currently selected node highlighted. The user should still able to expand and collapse.
I have tried to bind to PreviewSelected but the SelectedItem property still gets hit even if I switch e.handled = true and I lose the node highlighting on the currently selected node.
<
UserControl.Resources
>
<
ResourceDictionary
>
<
Style
x:Key
=
"PHToCItemContainerStyle"
TargetType
=
"{x:Type telerik:RadTreeViewItem}"
BasedOn
=
"{StaticResource RadTreeViewDefaultItemPlusMinusStyle}"
>
<
Setter
Property
=
"IsExpanded"
Value
=
"{Binding IsExpanded, Mode=TwoWay}"
/>
<
Setter
Property
=
"IsSelected"
Value
=
"{Binding IsSelected, Mode=TwoWay}"
/>
</
Style
>
<
DataTemplate
x:Key
=
"Measure"
>
<
TextBlock
Text
=
"{Binding Name }"
Style
=
"{StaticResource RadTreeViewItemSelectedTextBlockDefaultStyle}"
VerticalAlignment
=
"Center"
/>
</
DataTemplate
>
<
HierarchicalDataTemplate
x:Key
=
"Condition"
ItemTemplate
=
"{StaticResource Measure}"
ItemsSource
=
"{Binding Measures}"
>
<
TextBlock
Text
=
"{Binding Name}"
Style
=
"{StaticResource RadTreeViewItemSelectedTextBlockDefaultStyle}"
/>
</
HierarchicalDataTemplate
>
<
HierarchicalDataTemplate
x:Key
=
"ConditionGroup"
ItemTemplate
=
"{StaticResource Condition}"
ItemsSource
=
"{Binding Conditions}"
>
<
TextBlock
Text
=
"{Binding Name }"
FontWeight
=
"Bold"
Style
=
"{StaticResource RadTreeViewItemSelectedTextBlockDefaultStyle}"
/>
</
HierarchicalDataTemplate
>
</
ResourceDictionary
>
</
UserControl.Resources
>
...
<
telerik:RadTreeView
x:Name
=
"RadTree"
telerik:TextSearch.TextPath
=
"Name"
VirtualizingStackPanel.IsVirtualizing
=
"True"
VirtualizingStackPanel.VirtualizationMode
=
"Recycling"
ItemsSource
=
"{Binding ResultObject}"
Style
=
"{StaticResource RadTreeViewDefaultPlusMinusStyle}"
ExpanderStyle
=
"{StaticResource RadTreeViewDefaultPlusMinusExpanderStyle}"
ItemTemplate
=
"{StaticResource ConditionGroup}"
ItemContainerStyle
=
"{StaticResource PHToCItemContainerStyle}"
SelectedItem
=
"{Binding ResultObject.SelectedIndexItem}"
/>
dll version = 2014.1.331.45
<telerik:RadPane x:Name="rpIndexPane" CanUserClose="False" ContextMenuTemplate="{x:Null}" CanDockInDocumentHost="False" Header="Index"
telerik:RadDocking.SerializationTag="IndexPane" DataContext="{Binding}">
<ItemsControl DataContext="{Binding}" ItemsSource="{Binding ActiveJob.Patient.CurrentVisit.Sections.Items}" HorizontalContentAlignment="Stretch">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter/>
</ScrollViewer>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Background="{Binding Color}" Margin="1" Visibility="{Binding Visible, Converter={StaticResource BoolToVisConverter}}">
<TextBlock Text="{Binding Name}" Margin="3,5,3,5" HorizontalAlignment="Center"></TextBlock>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</telerik:RadPane>
<
DataTemplate
x:Key
=
"HeaderTemplate"
>
<
StackPanel
Orientation
=
"Horizontal"
>
<
Image
Margin
=
"0,0,3,0"
Source
=
"{Binding Screen.IconSource}"
Width
=
"16"
Height
=
"16"
"/>
<
TextBlock
Text
=
"{Binding Screen.Title}"
/>
</
StackPanel
>
</
DataTemplate
>
<
Style
TargetType
=
"{x:Type Controls:RadPane}"
>
<
Setter
Property
=
"HeaderTemplate"
Value
=
"{StaticResource HeaderTemplate}"
/>
<
Setter
Property
=
"TitleTemplate"
Value
=
"{StaticResource HeaderTemplate}"
/>
</
Style
>
public
class
ScreenViewModel
{
public
ScreenViewModel(IScreen screen)
{
Screen = screen;
}
public
IScreen Screen {
get
;
private
set
; }
private
RadPane _pane;
//this property is set in DockingPanesFactory.CreatePaneForItem method
public
RadPane Pane
{
get
{
return
_pane; }
set
{
_pane = value;
_pane.Content = Screen.View;
_pane.Header =
this
;
RadDocking.SetSerializationTag(_pane, Screen.ContentId);
}
}
//+some other irrelevant properties
}
//this is my model
interface
IScreen
{
UIElement View {
get
; }
string
Title {
get
; }
string
ContentId {
get
; }
ImageSource IconSource {
get
; }
}
public
ObservableCollection<ScreenViewModel> Screens {
get
;
set
; }
public
void
Load(
string
file, IScreenFactory screenFactory)
{
if
(!File.Exists(file))
return
;
Screens.Clear();
using
(var fs = File.OpenRead(file))
{
var doc = XDocument.Load(fs);
foreach
(var screenId
in
doc.Descendants(
"RadPane"
).Select(x => x.Attribute(
"SerializationTag"
).Value))
{
//some factory wich creates models by their IDs
IScreen screen = screenFactory.RestoreScreen(screenId);
Screens.Add(
new
ScreenViewModel(screen));
}
if
(Screens.Any())
{
fs.Position = 0;
//after this call all template the bindings break
_radDocking.LoadLayout(fs);
}
}
}