英文:
Keep information through different pages
问题
我正在使用WPF C#在不同页面之间进行导航,想知道如何在一页和另一页之间传递信息,但我也在使用Material Design来实现这一点。有什么想法?
我正在使用的代码可以在以下链接找到:
MaterialDesignInXamlToolkit/MainDemo.Wpf/TransitionsDemo/
英文:
im using wpf c# to navigate between various pages and i was wondering how information can be used from 1 page to another, but im using also material design to accomplish this. Any ideas?
The code im using can be found on:
MaterialDesignInXamlToolkit/MainDemo.Wpf/TransitionsDemo/
答案1
得分: 1
你考虑创建SharedDataService类吗?您可以创建服务的单例对象,具有所需的属性,并在需要使用此服务的地方注入它。
public class SharedDataService
{
string SharedProperty { get; set; }
}
现在在您的类中,您可以像这样使用它:
public class MyClass
{
private SharedDataService _mySharedService;
public MyClass(SharedDataService mySharedService)
{
_mySharedService = mySharedService;
}
public void UpdateSharedProperty()
{
SharedProperty = "MyClass中的新值";
}
}
通过这种方式,您可以从所有需要的类访问SharedDataService。
如果您不喜欢依赖注入,您可以创建静态SharedDataService类。
英文:
Do you think about creating SharedDataService class? You can create singleton object of the service with needed properties and inject it where you need to use same instance of this service.
public class SharedDataService
{
string SharedProperty {get; set;}
}
and now in you class you can use it like this
public class MyClass
{
private SharedDataService _mySharedService;
public MyClass(SharedDataService mySharedService)
{
_mySharedService = mySharedService;
}
public void UpdateSharedProperty()
{
SharedProperty = "New value from MyClass";
}
}
This way you can access SharedDataService from all needed classes.
If you don't like dependecy injection you can create static SharedDataService class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论