<pre lang="css">We have a Datagrid, as Show in the Above Image.
The 1st Row in the Datagrid in a Parent Record, on ComboBox selectionChanged event. the Two records are being populated as ChildRecords.
The FirstColumn in the DataGrid is a Combobox and its selectedValue comes from a Field, ItemId.
The problem is happening when The Grid is binding with the Child Records, the Combobox selection is always happening to be the Last ItemId for all Combobox's in this Column.
The result required:
The Each ComboBox in each Row should have the SelectedValue as of its own Record Set.</pre>
I need help to find (or make) a control for windows environment (xaml/wpf) that scroll up automatically lines of text in a specific speed. vertical scroll.
like a News Scroller of news sites...
Hi Mycroft. Apologies for taking this long to reply. Been a little busy. I tried the below and I get the SelectedItem but it does not get passed to "theSong". Am I going crazy or am I just missing the point completely here?
You are missing the point completely you are thinking like winforms, stop.
You should not/never be referencing the controls in the view but the collection it is bound to in you viewmodel or code behind. Stop trying to get the info from the list control and look in the SelectedSong property where you have bound the SelectedItem to!
Never underestimate the power of human stupidity
I have a requirement to display a collection of sections, each section needs needs to show a few combos, a couple of large textboxes, probably a grid and support drag and drop files.
I was thinking of using a listbox of user controls, the user control would be an expander (telerik) with all the bits in it.
My issues is how to put together the collection/control/viewmodel. Building the VM that accepts a SelectedSection and loads the static lists for the combos etc is not a problem. I can then bind the view datacontext to the viewmodel.
I would then use the UC as the datatemplate of the listbox. How do I bind the SectionsList collection to the listbox and the UC data template.
Are there any good examples of this!
Never underestimate the power of human stupidity
You should not expose a collection of user controls, or any control for that matter. Define a class called Section (whatever the hell that is) that contains all the data for a section. Then define an ObservableCollection<Section> and expose that from your VM and bind it to the ListBox ItemsSource. Then simply define the ItemTemplate for the ListBox and you are good to go.
Your ItemTemplate would define the controls and their layout and bind them to the Section object which will be the ListBoxItem content.
Not quite sure what you mean. When you say "UC", you should be using a DataTemplate that defines that "UC". When you say "VM" for each item, that would be your Section object. In fact, if you want to argue semantics, your DataTemplate could just be your user control. It would inherit the DataContext.
Sounds like we are saying pretty much the same thing, but you don't like my semantics lol .
Ok, so Section is a model an observable POCO. Check.
UC UserControl = DataTemplate for an item.
Here is where you are arguing semantics. You say you need a VM for binding to the UC UserControl / DataTemplate... I'm agreeing with you, but saying it needs to be part of Section. Then you can bind as normal.
If you still want to argue semantics, you can do something like:
and then in your XAML, you could either do:
<MyUserControl /> and the DataContext will point to the Section object and you can reference the VM from there using Path=ViewModel.Blah;
and the MyUserControl will only get the ViewModel rather then the whole Section object. Either way works, but the VM / sub object / whatever you want to call it, has to be part of Section since that is what you are binding to.
If you don't want to do that for whatever reason, the only other thing you can probably do if you want to get all tricky is use DataTemplates to instantiate the VMs based on something in the Section object, but that would require modifying how the item creation works and the end result will be that you could have just stuck your "VM" into the section object and achieved the same thing and kept a few more hairs .
Calling something a ViewModel is just arguing semantics. Its just some random (generally observable) object that the DataContext points to. In the MVVM world its just some random (always observable) object that derives from "ViewModelBase" or something similiar.
The VM that owns the listbox would have the ObservableCollection<Section>. Section would then contain the VM / whatever for the UserControl.
I created a user control and I want to display it as the content of a combobox.
I tried to wire up the user control inside the combo, but I see nothing, and the user control's view model isn't being instantiated.
JobListView is a custom tree with search conntrols. How do I make the ComboBox use the JobListView as its content? Right now, when I run it and open the combo, nothing appears.