I have a WPF application with an Expander Control. I want the Expander Control to expand ONLY based on IsMouseOver event. I was able to enable the IsMouseOver behavior by implementing the corresponding trigger in ControlTemplate.Triggers. But I can't figure out how to disable the IsPressed/OnMouseClick events. Any advice on how to do is greatly appreciated. Thanks.
You could handle the PreviewMouseLeftButtonDown
event for the ToggleButton
that is called "HeaderSite" in the default template:
private void HeaderSite_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
=> e.Handled = true;
XAML:
<ToggleButton x:Name="HeaderSite" PreviewMouseLeftButtonDown="HeaderSite_PreviewMouseLeftButtonDown" ContentTemplate="{TemplateBinding HeaderTemplate}" ... />
Remember that XAML is a markup language and that you should implement this kind of behaviour in a programming language such as C#.
If your template is defined in a ResourceDictionary
, you should add a code-behind class to it and defined the event handler there.