如何将“打包图标”用作鼠标光标?

时间:2019-02-11 23:53:45

标签: c# wpf material-design-in-xaml

我有以下代码,用于提供有关拖放操作的鼠标光标反馈。它使用本地光标文件。

private void UserControl_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
    if (e.Effects == DragDropEffects.None)
    {
        e.UseDefaultCursors = true;
        e.Handled = true;
        return;
    }

    if (cursor == null)
    {
        StreamResourceInfo s = Application.GetResourceStream(new Uri(@"pack://application:,,,/Schedule/Week/ContentCopy.cur", UriKind.RelativeOrAbsolute));
        cursor = new Cursor(s.Stream);
        Mouse.SetCursor(cursor);
        e.UseDefaultCursors = false;
    }
    e.Handled = true;
}

现在,我想更改此代码以使用Material Design in Xaml library中的“打包图标”。

我可以在代码中得到这样的图标:

using MaterialDesignThemes.Wpf;

var icon = new PackIcon { Kind = PackIconKind.DocumentCopy };

但是我不知道如何将其转换为适合Cursor对象使用的流。

1 个答案:

答案 0 :(得分:1)

PackIcon是一个Control,它包装了一个Path元素,不能直接用作光标。

您可以做的是尝试使用here中的@Ray Burns的PackIcon方法从ConvertToCursor元素创建光标。

另一种选择是简单地拍摄图标的屏幕快照,将其另存为图像并使用某种工具从中创建光标。在线上有很多“将png转换为光标”和类似的工具。