I have in my XAML:
<HierarchicalDataTemplate DataType="{x:Type vm:MyViewModel}">
<StackPanel Orientation="Horizontal" Margin="-5,0,0,0">
<Border Name="SelectedBorder" CornerRadius="3" BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource AncestorType=TreeViewItem}}" BorderThickness="0.5" >
<StackPanel Orientation="Horizontal">
------> <CheckBox Margin="0,1,0,0" IsChecked="{Binding Path=IsOn}"/>
<Image VerticalAlignment="Top" Margin="3,0,0,0" Source="{ Binding Path=Image, Converter={StaticResource imageConverter} }"/>
<TextBlock Margin="3,1,0,0" Width ="150" Text="{Binding Path=Name}" TextWrapping="Wrap"
......
This is used in a tree as nodes.
In the tree, I handle PreviewMouseDown(object sender, MouseButtonEventArgs e)
to receive the click even if it happened on a control.
void TreeviewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (e.OriginalSource is System.Windows.Controls.CheckBox)
{
******* THIS NEVER HAPPENS
}
When clicked on Image or TextBox on the treenode:
sender
is TreeViewItem, e.Source
is ContentPresenter , e.OriginalSource
is Image or TextBox. This is fine.
However, if I click on CheckBox, the e.OriginalSource is Microsoft.Windows.Themes.BulletChrome
.
I know this is somehow related to windows theme (PresentationFramework (""|"Aero"|"Royale"|"Luna").dll
- But why is this, I want to work with my CheckBox here.
- How can I get the CheckBox? (BulletChrome.TemplateParent??)
- Can I rely on this, so when user clicks on CheckBox (even on a non-aero machine, like old windows, etc), it always will be BulletChrome?
- Better to use?
if (e.OriginalSource is System.Windows.Controls.CheckBox || e.OriginalSource is Microsoft.Windows.Themes.BulletChrome)
- To call
e.OriginalSource is Microsoft.Windows.Themes.BulletChrome
I need a reference to PresentationFramework.Aero.dll or PresentationFramework.Royale.dll. Does it matter which one?