Я решил написать многоразовое поведение, HTH:
Namespace Components
Public NotInheritable Class TreeViewBehavior
Public Shared Function GetIsTransparent(
ByVal element As TreeViewItem) As Boolean
If element Is Nothing Then Throw New ArgumentNullException("element")
Return element.GetValue(IsTransparentProperty)
End Function
Public Shared Sub SetIsTransparent(ByVal element As TreeViewItem,
ByVal value As Boolean)
If element Is Nothing Then Throw New ArgumentNullException("element")
element.SetValue(IsTransparentProperty, value)
End Sub
Public Shared ReadOnly IsTransparentProperty As DependencyProperty =
DependencyProperty.RegisterAttached("IsTransparent", GetType(Boolean),
GetType(TreeViewBehavior),
New FrameworkPropertyMetadata(False,
AddressOf IsTransparent_PropertyChanged))
Private Shared Sub IsTransparent_PropertyChanged(
ByVal sender As Object, ByVal e As DependencyPropertyChangedEventArgs)
Dim tvi = DirectCast(sender, TreeViewItem)
Dim isTransparent = CBool(e.NewValue)
If isTransparent Then
AddHandler tvi.Selected, AddressOf tvi_Selected
Else
RemoveHandler tvi.Selected, AddressOf tvi_Selected
End If
End Sub
Private Shared Sub tvi_Selected(ByVal sender As Object,
ByVal e As RoutedEventArgs)
Dim treeViewItem = DirectCast(sender, TreeViewItem)
If Not treeViewItem.IsSelected Then Exit Sub
treeViewItem.Dispatcher.Invoke(
Sub(tvi As TreeViewItem) tvi.IsSelected = False,
System.Windows.Threading.DispatcherPriority.Send,
treeViewItem)
End Sub
End Class
End Namespace
Использование:
<Window xmlns:components="clr-namespace:WpfApplication.Components">
<TreeView>
<TreeView.ItemContainerStyle>
<Style TargetType="TreeViewItem">
<Setter
Property="components:TreeViewBehavior.IsTransparent"
Value="True" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
</Window>