Well, you're not using the MVVM pattern. You should implement the MVVM pattern when you're using WPF (although you sometimes can take shortcuts and not implement the necessary parts to get the job done).
You can learn about MVVM from the links I posted here[^].
So I suggest you create a class PhysicalPropertyViewModel that has the following main properties
- a property AvailableUnits that returns the available enum values for the property (to feed the combobox)
- and a property SelectedUnit that is bound to the SelectedItem of the combobox
when is set, it changes the DisplayValue property value accordingly
- a property DisplayValue which is the value to display according to the selected measurement unit
The TreeView article is how I initially understood most of the MVVM concept. Go read it and then read the MSDN Magazine article. Then read this reply again. After this, if you don't understand what I mean, tell me and I'll try to be more clear. Have a nice day.
Thanks Eslam Afifi, your suggestion to create a property AvailableUnits was the food for thought I needed. It works perfectly.
I am not quite sure if I actually use something like a MVVM pattern. I have a wrapper class for the binding to the GUI. Extended by the AvailableUnits property it works.
Thanks for your help.
Glad to help. What you're doing is similar to (if not actually is) the MVVM pattern. MVVM is short for Model-View-ViewModel. A ViewModel is basically a wrapper around a Model for a View to expose the model's properties to the view and to pass commands from the view to the model.
Using the MVVM pattern can help in virtually all cases avoid stuff like that. Please see this post[^].
But if you really need to get it done the way to described, the ListBox has a property called Items. Then for each item, you can access it's visual tree and search for the element you want by its name using the FindName method (I'm not fully sure about that since I did this kind of stuff only once when I first started learning WPF).
P.S. stepping into the debugger and seeing the items' structures using the Immediate Window or a debugger visualizer like Mole[^] can help you get this done quickly.
i have text box to enter the name, add button,listbox will display the added records,button to save the record.
when i entered the name and clicked add button, it will add the data to database and text box will be cleared.
like that i adding some records and those records will be binded to listbox and it will display the records in the list box.
now i am trying to edit the record so i just selecting the record in listbox. by doing that i will get the corresponding data in the same text box(Which i used to enter the data).i binded the listbox selected item
to the text box.
then i edited text box and i clicked save button, its saved.
while i saving it i am clearing the text box but due to clearing the text box in save button is clearing the data which is binded in the list box , so the listbox displays the empty data for that record.
Yes, handling the paint event is correct. What he is doing will work, so long as no other window ever obscures his window, or he doesn't ever minimise and reshow it. Otherwise, what he drew, will disappear.
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
Last Visit: 31-Dec-99 19:00 Last Update: 5-Dec-23 19:07