Is there any way to achieve something like office undo drop down (image bellow) ? I mean, i want to highlight previous item when user mouse over item other than first ? I tried some control from FluentRibbon but so far without luck..
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Guess you need something like this:
In most cases designing a control like this is done in Blend. However, if you don't know how to use Blend, you can still achieve the similar results with just XAML and the code-behind, but you have to do more work.
We start by creating a class called
CustomListBoxItem
which inherits fromListBoxItem
. Then, we define a dependency property, which is used for highlighting items in the listbox:Then we add a listbox and define a style for it in XAML:
where
local
is the namespace in whichCustomListBoxItem
is defined. This is all we need for the XAML part, the real magic happens in the code behind.The
listBox_MouseMove
event handler looks like this:And the
IsMouseOverItem
helper method, which is used to determine if the cursor is on an item, is defined like this:And finally the
listBox_SelectedChanged
event handler which acts as the click handler for the ListBox:And boom, we're done. We can now add some items to the ListBox in the class constructor:
Note that I used a random color as the highlight color in XAML. Feel free to change it and give it a try.