1

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

  1. But why is this, I want to work with my CheckBox here.
  2. How can I get the CheckBox? (BulletChrome.TemplateParent??)
  3. 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?
  4. Better to use? if (e.OriginalSource is System.Windows.Controls.CheckBox || e.OriginalSource is Microsoft.Windows.Themes.BulletChrome)
  5. 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?
Community
  • 1
  • 1
Zoli
  • 841
  • 8
  • 31
  • Maybe you should be using `Source` instead of `OriginalSource` (or even `sender` for that matter). [`OriginalSource`](https://msdn.microsoft.com/en-us/library/system.windows.routedeventargs.originalsource.aspx) is for *pure* hit-testing. – Leandro Dec 05 '16 at 15:38
  • 1
    No, `sender = TreeViewItem` and `e.Source = ContentPresenter `. Updated my question with these details, please see. `e.OriginalSource` is proper for TextBlock or Image, but when CheckBox is clicked, OriginalSource is BulletChrome . – Zoli Dec 06 '16 at 08:26

0 Answers0