2

I am trying to get a custom cursor for my WPF application. I already have the .cur file in the Resources. In the xaml, I mentioned the resource dictionary something like this:

<Window.Resources>
        <ResourceDictionary>
            <FrameworkElement x:Key="KinectCursor" Cursor="Resources/KinectCursor.cur"/>
            <FrameworkElement x:Key="KinectCursor16" Cursor="Resources/KinectCursor16.cur"/>
        </ResourceDictionary>
    </Window.Resources>

In the code-behind, I tried to the set the Mouse.OverrdeCursor property to this cursor but it is throwing exceptions.

 private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Mouse.OverrideCursor = this.Resources["KinectCursor"].Cursor;
            Mouse.OverrideCursor = ((FrameworkElement)this.Resources["KinectCursor"]).Cursor;
            //DisplayArea.Cursor = Cursors.Hand;
        }

Exception Message:

XAMLParseException occured.
'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' 
threw an exception.' Line number '7' and line position '14'.
0

1 Answer 1

2

This error occurrs sometimes if you pass a wrong relative icon path. Try to do it like this:

...
<FrameworkElement 
    x:Key="KinectCursor" 
    Cursor="pack://application:,,,/(AssemblyName);component/Resources/KinectCursor.cur"/>
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.