lundi 5 décembre 2016

WPF Checkbox vs BulletChrome

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"
......

I handle PreviewMouseDown(object sender, MouseButtonEventArgs e) to check if click happens on the CheckBox (for whatever reason..)

    void TreeviewItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.OriginalSource is System.Windows.Controls.CheckBox)
        {
           ******* THIS NEVER HAPPENS
        }

I debugged, and 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?



Aucun commentaire:

Enregistrer un commentaire