How does WPF use custom mouse resources in code?

Source: Internet
Author: User

If you want to use a custom mouse in XAML, simply set cursor = "/asserts/hand. Ani" in the label,

However, ifCodeThis. cursor = new cursor ("Mouse resource path") is required. Here, the [Mouse resource path] must use an absolute path,

This is not a problem. Another method is to use (I have not verified ):

 
Streamresourceinfo Sri = application. getresourcestream (New uri ("/assets/cursor/hand. ani ", urikind. relative); cursor customcursor = new cursor (SRI. stream); this. cursor = customcursor;

I don't feel very good, but I accidentally saw it on the Internet. A resource dictionary implementation method is as follows:

 
// Add to resources: <window. resources> <resourcedictionary> <textblock X: Key = "cursorgrab" cursor = "Resources/cursors/grab. cur "/> <textblock X: Key =" cursormagnify "cursor =" Resources/cursors/magnify. cur "/> </resourcedictionary> </window. resources>

 

// Example of embedded cursor referenced in code: If (selectedtool = "hand") mycanvas. cursor = (textblock) This. resources ["cursorgrab"]). cursor; else if (selectedtool = "magnify") mycanvas. cursor = (textblock) This. resources ["cursormagnify"]). cursor; else mycanvas. cursor = cursor. arrow;

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.