I have some custom cursors in my application. I used informations found on the second answer here to create my custom cursor. This works well. My problem is that when I move my mouse over a Popup, the mouse appears as the default Cursor. Strange thing is that when i move my mouse out o开发者_如何学Gof the Popup, my custom cursor come back. Ok so i instanciate my cursor like so :
UserControl.xaml :
<TextBlock
x:Name="SupprimerV"
x:Key="SupprimerV"
Cursor="../Utils/Supprimer.cur"/>
In the UserControl.xaml.cs :
this.Cursor = ((TextBlock)this.FindResource("SupprimerV")).Cursor;
Then i call my own control SimplePopup which derive from Popup like so :
_pop = new SimplePopup(this); //Irrelevant information omitted
SimplePopup.cs :
public simplePopup(FrameworkElement relativeTo)
{
this._relativeTo = relativeTo;
this.Cursor = relativeTo.Cursor; //Trying to set the cursor of the popup but dosent work
...
}
I tried to set the popup cursor but it dosent seem to work. The cursor work fine on my UserControl but fail when the mouse is over the Popup.
Im i missing something? Is ther something preventing my cursor from working correctly on a Popup?
Thnx for your help, Sorry for spelling mistakes ^^
Ok so i found out a way to make my cursor appear correctly into my popup. My SimplePopup use a border as its child element. I tried to set that border's Cursor to the _relativeTo cursor like this :
popBorder.Cursor = _relativeTo.Cursor;
and it worked I Was wondering why so i did a bit of research and i found this interesting piece of text :
Pro WPF in c# 2010 - Chapter 6 page 186 : "you must set the Background property if you want to see your content, because it won’t be inherited from your window and you need to add the border yourself (the Border element works perfectly well for this purpose)." http://archon.name/files/books/programming/Apress.Pro.WPF.in.C%23.2010.Windows.Presentation.Foundation.in.NET.4.pdf
So clearly, the popup wont inherit any of its creator's properties (including the cursor).
I think since the popup has no apperance at all, that his cursor's property dosent propagate down its element tree...
It surprises me since in my main application i set the cursor to the first element in the tree and it seems to propagate well or at least it can appear over child elements.
I wonder if ther is other reason or if this behavior appear's anywhere else in WPF.
精彩评论