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.
I want a StackPanel to be populated by one button for each entry in an ArrayList. I can set up these buttons from the ArrayList using a foreach sequence. But how would I define the corresponding event handlers?
Each button calls the same event (Command) and passes in the commandparameter which should be bound to the object in the collection. So the method receives and object that can then be cast as the item in the collection.
Never underestimate the power of human stupidity