I want to create a Style
for a WPF ListBox
that includes a Button
in the ControlTemplate
that the user can click on and it clears the ListBox
selection.
I dont want to use codebehind so that this Style
can be applied to any ListBox
.
I have tried using EventTrigger
s and Storyboard
s and it has proved problematic as it only works first time and stopping the Storyboard
sets the previous selection back.
I know I could use a user control but I want to know if it is possible to achieve this using only a Style
.
相关问题
- VNC control for WPF application
- How to stylize text in an alert box? [duplicate]
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- XAML: Applying styles to nested controls
It is not possible to achieve this using XAML and only the classes provided by the .NET framework. However you can still produce a reusable solution by defining a new command (call it
ClearSelectionCommand
) and a new attached property (call itClearSelectionOnCommand
).Then you can incorporate those elements into your style.
Example:
Example usage - XAML:
Example usage - Code Behind: