我有以下代碼,我用它來提供有關拖放操作的鼠標光標反饋。它使用本地游標文件。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;}現在,我想將此代碼更改為使用 Xaml 庫中的材質設計中的包圖標。我可以在代碼中得到這樣的圖標:using MaterialDesignThemes.Wpf;var icon = new PackIcon { Kind = PackIconKind.DocumentCopy };但我不知道如何將其轉換為適合對象使用的流。Cursor
2 回答

aluckdog
TA貢獻1847條經驗 獲得超7個贊
我能夠使用類似于此處描述的光標創建方法(在mm8的答案中的鏈接中沒有步幅問題)。
此外,使用 PackIconControl 的代碼如下所示。
PackIconControl pic = new PackIconControl() { Kind = PackIconMaterialKind.CursorDefaultOutline, Width = 16, Height = 16};
pic.Style = Application.Current.FindResource(typeof(PackIconControl)) as Style;
pic.Foreground = Brushes.White;
m_MyCursor = CursorUtil.ConvertToCursor(pic, new Point(4,1));
一些評論:
我必須顯式指定樣式,因為我尚未將控件添加到可視化樹中。我的應用的資源字典中包含 mahapps 樣式。
CursorUtil.ConvertToCursor是上述鏈接中提到的方法。
Point(4,1) 將光標的熱點放在大約 PackIconMaterialKind.CursorDefaultOutline 箭頭的尖端。其他圖標將具有不同的熱點,這些熱點適用于其特定形狀。
- 2 回答
- 0 關注
- 126 瀏覽
添加回答
舉報
0/150
提交
取消