设置的动态绑定?
我面临一个问题,我有一个具有多个设置文件的应用程序,但它们具有完全相同的字段。
示例:
- Profil1.settings
- Profil2.settings
- Profil3.settings
我想在设置窗口 XAML 中执行的操作是动态更改每个配置文件的绑定源。
目前,我的 XAML 绑定如下所示:
SelectedValue="{Binding Source={x:Static Local:Properties.Profil1.Default}, Path=CurrentProfil, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
我的问题是如何用“Profil2”替换“Profil1”,而不通过后面的代码为每个控件一一重新制作所有绑定?是否可以在 XAML 绑定源中使用一些反射变量,而不是简单地使用 Profil1 类型或 Profil2 类型更改该变量的类型?
任何人都可以帮我解决这个问题吗?
提前致谢。
I am facing a problem, I have a application with several setting's files but which have exactly the same fields.
Sample :
- Profil1.settings
- Profil2.settings
- Profil3.settings
What I'd like to do in my setting window XAML is to dynamicaly change the binding source for each profile.
At the moment my XAML binding look like this :
SelectedValue="{Binding Source={x:Static Local:Properties.Profil1.Default}, Path=CurrentProfil, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
My problem is how to replace the "Profil1" by "Profil2" without remaking all my Binding one by one for each controls via my code behind ? Is that possible to use some king of reflection variable in the XAML binding source and than simply change the type of that variable with Profil1 type or Profil2 type ?
Anyone can help me about this ?
Thank in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要做的是将设置窗口的 DataContext 设置为适当的配置文件。您可以随心所欲地执行此操作,但通过这样做,您的所有绑定都将指向该对象。要使绑定像现在一样工作,您需要执行以下操作:
What you want to do is set the DataContext of your settings window to the appropriate profile. You can do it anyway you want, but by doing so, all your bindings would point to that object. To make the bindings work like you have now, you'd do: