我在Cursor
中添加了MainWindow.xaml
个文件作为资源,如何从代码中驻留在此窗口内的Border
元素中访问此资源?
<Window.Resources>
<ResourceDictionary>
<FrameworkElement x:Key="OpenHand" Cursor="pack://application:,,,/Resources/openhand.cur"/>
</ResourceDictionary>
</Window.Resources>
<Grid x:Name="AppInterface">
// A Border is added here by code
// I want to be able to access the above resource from Border in code-behind
</Grid>
答案 0 :(得分:3)
试试这个:
var elementhand = Application.Current.MainWindow.Resources["OpenHand"] as FrameworkElement;
答案 1 :(得分:1)
您可以使用Application.FindResource
按名称查找。
FrameworkElement resource = Application.Current.FindResource("OpenHand");