Mvvm - How to capture in the ViewModel, the UI's data-bound Control's Name/Id, using a Parameter Command? Is there a clear cut way I'm missing?

时间:2016-11-12 05:53:54

标签: c# wpf mvvm combobox

Mvvm, Wpf, VS2015 Hi All! I have googled this till my fingers bleed! But just hacks and work-arounds, or partial use of code behind. My Wpf-Mvvm app uses Speech Synthesis. Each button, (and in the next iteration, buttons using the selectedItem Index of Lists or ComboBoxes, to select the content(text)to be synthesized) specifies different content to be synthesized. Sticking with Mvvm principles, in my viewModel, I need to capture which button, based on the List or ComboBoxes' SelectedItem/Value that is bound to the Parameter Command. Why? So I can have the app synthesize the content(text/words)the user selects to hear. If not, I have to make separate commands and speech synthesizer methods for each. There must be a simple clear-cut way. What am I missing here?

I thought of updating the Model's properties to reflect user's selection and use User Settings to persist,but have not tried yet. Otherwise the Model's properties are accessible so far as encapsulation-wise to the ViewModel, but the property values from the Model still are not visible in viewModel. I need the command bound control's ID/Name to route the content to be synthesized based on the model's class properties. But when I instantiate the model from the viewModel, the model's properties are not there. I presume instantiating the Model class object from the viewModel, is in a different memory location, than the Model. So I will try using User Setting's persistence for these properties, if no one else has a better way. There has to be a clear solution to this, I hope :)
I know the View and ViewModel are supposed to not need to know what the other is doing. In this case though, I clearly need the List or ComboBoxes' Id or Name and their SelectedItem index. I also need the button's Id or Name, because I have several groupings of content to choose from, and several buttons starting the synthesizing method. Example: If the text content of an announcement to be synthesized, held in separate XML(SSML) files with identifier key values of 941, 23, 508, etc., I need to know which the User Selected to hear. I imagine simply capturing in the viewModel, the Data-bound List/ComboBoxes' Selected ID index would suffice. Thank you so very much for your help. -Flazz

0 个答案:

没有答案