Hi!
I have created a very basic user control. It has 3 textboxes andits purpose is to present a string that is split up into three different values. Say the string is xxx-AAAA-BBB. Then the user control will split this string and present it's values in different textboxes. There should be a binding also so if the user changes the text, it should be preserved and put back into the single string when user clicks save. We use MVVM in the application. Here are my thoughts:
1) Create a user control with a viewmodel class that has 4 properties (part1, part2, part3 and WholeFormattedString).
2) part 1-3 will be set in the constructor and are based from the WholeFormattedString. The property WholeFormattedString has a get and set property and the Get simply puts part1-3 together and return a string. The set splits the incoming string in 3 strings and set the private members that are bound to the textboxes. It is the parent that fetches the value from the db and should just pass it along to the user controls viewmodel.
3) Does the usercontrol really need a viewmodel? it makes sence since there is logic involved in splitting the string and this UC should be used on many different forms.
Is there a better way to solve this? The binding seems pretty basic, Im more concerned about how to assign the values from the parent view to the usercontrol view. And also I need a binding between the usercontrol WholeFormattedString and the parentview.WholeFormattedString since it is the parentview.WholeFormattedString that is used when the user presses save on the form.
kind regards
Henrik
I have created a very basic user control. It has 3 textboxes andits purpose is to present a string that is split up into three different values. Say the string is xxx-AAAA-BBB. Then the user control will split this string and present it's values in different textboxes. There should be a binding also so if the user changes the text, it should be preserved and put back into the single string when user clicks save. We use MVVM in the application. Here are my thoughts:
1) Create a user control with a viewmodel class that has 4 properties (part1, part2, part3 and WholeFormattedString).
2) part 1-3 will be set in the constructor and are based from the WholeFormattedString. The property WholeFormattedString has a get and set property and the Get simply puts part1-3 together and return a string. The set splits the incoming string in 3 strings and set the private members that are bound to the textboxes. It is the parent that fetches the value from the db and should just pass it along to the user controls viewmodel.
3) Does the usercontrol really need a viewmodel? it makes sence since there is logic involved in splitting the string and this UC should be used on many different forms.
Is there a better way to solve this? The binding seems pretty basic, Im more concerned about how to assign the values from the parent view to the usercontrol view. And also I need a binding between the usercontrol WholeFormattedString and the parentview.WholeFormattedString since it is the parentview.WholeFormattedString that is used when the user presses save on the form.
kind regards
Henrik