[英]WPF - Global Properties and User Controls
Greetings 问候
I have a Main Window which will hold multiple User Controls. 我有一个主窗口,其中包含多个用户控件。 I will give you a better view with an example picture: 我将通过示例图片为您提供更好的视图:
<!--Player 1-->
<local:ucRaces x:Name="ucRacesP1" Width="78" Height="33" Visibility="Hidden" />
<Image Name="imageRacePlayer1" Height="27" Width="27" />
<!--Player 2-->
<local:ucRaces x:Name="ucRacesP2" Width="78" Height="33" Visibility="Hidden" />
<Image Name="imageRacePlayer2" Height="27" Width="27" />
Now what I want to do is, when a person selects a value in UC3 the properties for player1 need to be set. 现在我要做的是,当一个人在UC3中选择一个值时,需要设置player1的属性。 When a value gets selected in UC4 I need the properties for player2 to be set. 当在UC4中选择一个值时,我需要设置player2的属性。 I was thinking to do this with properties but when searching for Properties and WPF I stumbled upon Dependency Properties. 我本来想使用属性来执行此操作,但是在搜索属性和WPF时,我偶然发现了依赖属性。 Which started to confuse me a bit, would I need to use normal Properties or these Dependency Properties. 这让我有些困惑,我需要使用普通的属性还是这些依赖项属性。
How can I know if I have to set the player1 values or the player2 values (this depends from which UserControl sends the data)? 我怎么知道我是否必须设置player1值或player2值(这取决于从哪个UserControl发送数据)?
How would I save these values best for the entire application? 如何最好地为整个应用程序保存这些值?
Is putting the User Controls on hidden at the start (due to positioning) the best way or is there a better alternative? 是在开始时(由于定位)使用户控件处于隐藏状态,还是最好的方法?
Thank you for your time reading my question(s)! 感谢您抽出宝贵的时间阅读我的问题!
i think , your statring point is 我认为,您的观点是
Depending on which button is pressed on the image one of these controls becomes visible 根据在图像上按下了哪个按钮,这些控件之一将变为可见
1- There are certain buttons on the image and user can click on the image. 1-图像上有某些按钮,用户可以单击图像。
2- You can make use of ICommand interface to exceute the specific command in UI ie if user press Palyer1 , you cna execute Player1Command if user presses Player2 , you can execute Player2Command. 2-您可以使用ICommand界面执行UI中的特定命令,即,如果用户按下Palyer1,则可以执行Player1Command;如果用户按下Player2,则可以执行Player2Command。
3- There may be the duplication of code in player1 and player2 but don't worry about it , you can always refactor the code first thing is to dispatch the command to the respective command handler. 3-在player1和player2中可能有重复的代码,但不必担心,您始终可以重构代码,首先是将命令分派到相应的命令处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.