简体   繁体   English

如何访问Silverlight 4中App.xaml.cs中创建的自定义属性

[英]How to access custom property created in App.xaml.cs in Silverlight 4

I have created my own custom property in app.xaml.cs file I require to access this property in one of my viewmodel. 我在app.xaml.cs文件中创建了自己的自定义属性,我需要在我的一个viewmodel中访问此属性。 When i try to access via Application object it does not show up. 当我尝试通过Application对象访问时,它不会显示。 Can anyone help me with this. 谁能帮我这个。

Regards 问候

Use Application.Current to access custom property you have crated. 使用Application.Current访问您已创建的自定义属性。

var currentApp =  Application.Current as App;
currentApp.YourPropertyName = "WhateverYouWant";

Read this article on MSDN with example on how to do it. 阅读MSDN上的这篇文章,并举例说明如何操作。

或者只是Application.Current.Properties["YourSavePropertyKey"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM