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" />
- UC3 and UC4 are the same User Control
- UC3 has been given the name ucRacesP1 (Hidden by default)
- UC4 has been given the name ucRacesP2 (Hidden by default)
- Depending on which button is pressed on the image one of these controls becomes visible.
Now what I want to do is, when a person selects a value in UC3 the properties for player1 need to be set. When a value gets selected in UC4 I need the properties for player2 to be set. I was thinking to do this with properties but when searching for Properties and WPF I stumbled upon Dependency Properties. 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)?
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.
2- You can make use of ICommand interface to exceute the specific command in UI i.e. if user press Palyer1 , you cna execute Player1Command if user presses Player2 , you can execute 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.
精彩评论