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.
Why would it show anything? Think about what your XAML is doing. You set the ComboBox.ItemTemplate to show a views:JobListView. You just said "I want to render each item (in both the edit box and the drop down list) as a views:JobListView". So, if you have 10 items, you are going to get 10 views:JobListView plus another one in the edit box. Probably not what you meant .
As I have mentioned to you in the past, you really need to aquire a tool that will allow you to dump out control templates, so you understand how they are put together so you can do these types of mods as you get more advanced.
I would highly recommend you install Expression Blend Preview since its now free and allows you to dump out control templates easily as well as modify them visually.
Also, in your response to the other guy, you said you didn't set the combo box ItemsSource to anything and wanted the JobListView to retrieve everything. That won't work on a conceptual level. How is the edit box in the combo box going to display the selected item when it knows nothing about the collection?
You need to have the VM that owns the combo box own the collection and set the combo box ItemsSource to it. The edit box will show the selected item and the popup view will render as your JobListView.
I'm not going to post the ComboBox control template here since its quite large (200+ lines of XAML), but I did dump it out for discussion purposes.
There isn't an easy way to style the drop down list because its essentially an ItemsPresenter and doesn't have any built in templates for that.
You *might* be able to wait for the combo box template to be applied and then find the "DropDownScrollViewer" control by name and replace its content with your control. I haven't tried this, so its possible it won't work. If I was doing this task, I'd probably try it first though. Otherwise, it looks like you are going to have to dump out the control template and replace the ItemsPresenter with your joblistview.
There's your problem - your control is only ever using a single instance of the WebBrowser control, no matter how many instances of your control you create.
It looks like the only reason you've made it static is so that you can access it from the DependencyPropertyChanged events. All you need to do is cast the DependencyObject parameter to your ExtWebBrowser class, and you'll be able to access non-static fields, properties, and methods.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Hi there i have recently decided that i wanted to start playing around with app development. I was woundering if anyone can point me to any good information sources for such task. I dont know any xaml or silverlight so im learning from the ground up. Any books you can recommened, web sites, anything really.
Last Visit: 31-Dec-99 18:00 Last Update: 25-Jul-17 21:22