I have a Expander
in DataGrid
.
I want to instead click behavior, but it need to know IsSelected itself.
Then, use double-click expand.
I need a method easily to implement.
Have any idea?
If you want to double-click to expand/collapse the Expander
, you could handle its Loaded
event, get a reference to the ToggleButton
header button and then handle its PreviewMouseLeftButtonDown
like this:
private void Expander_Loaded(object sender, RoutedEventArgs e)
{
Expander expander = sender as Expander;
ToggleButton tb = FindVisualChild<ToggleButton>(expander);
if (tb != null)
{
tb.PreviewMouseLeftButtonDown += (ss, ee) =>
{
ee.Handled = ee.ClickCount < 2;
};
}
}
XAML:
<Expander Header="Expand/Collapse..." Loaded="Expander_Loaded">
<TextBlock>some content...</TextBlock>
</Expander>