I’ve a table in a database where I need to show all the rows’s content (as a TextBlock) and to the right of each TextBlock I need to show a TextBox so the user can enter a value (a number) for each row and also I need to be able to change the color of any TextBox when the value provided by the user is negative.
Can someone give me a clue with this?
PD: I’m using WPF with Prism 4 and MVVM pattern and VS2010 Ultimate
I won’t give you a complete solution, but I can point you in the right direction.
I start by creating a data structure that contains properties for
NameandValue, and that implements INotifyPropertyChanged for Property Change notification.Next in the
ViewModel(or possiblyModel), I would make would be anObservableCollection<MyDataObject>, and populate it with the data from the database.In the XAML, I would use an ItemsControl bound to the collection, and overwrite the
ItemTemplateto render each item as either a HorizontalStackPanelor aGrid, containing theLabelandTextBoxFor the
TextBox.Foregroundproperty, I would bind it to the same value thatTextBox.Textis bound to, except I’d also use a IValueConverter in the binding which checks to see if the value is above or below 0, and returns the correct color. Since it is a binding, it will automatically update whenever the value changes.