tell wpf how to render on tab change - wpf

I have an itemscontrol in a tabcontrol.
I bind my viewmodel to the itemssource of it and use a usercontrol as the itemstemplate.
When I run the programm wpf renders the itemscontrol not until I click on the tab it's in.
As I have a lot of items to render my program freezes for 10 secs.
Question:
Where can I tell my application for example to render one item in my itemssource, update my view and then render one item again and so on?

Related

WPF TabControl - In need of a default message before tabs load

I have a WPF TabControl who's TabItems are MEF'd in at run time. However, they are MEF'd in only when a certain item in a left-hand treeview is selected. What I'd like to do is display a centered message inside the TabControl indicating "No Active Scenario Selected". I tried adding a TextBlock inside the TabControl but what I got was a TabItem instead. Any ideas?
One way to do this is simply by putting a TextBlock on top of the TabControl and show it when the TabControl doesn't have any Tabs added.
You can bind the Visibility of the TextBlock to the HasItems property of the TabControl and use a value converter (BooleanToVisibilityConverter or your own implementation) to show and hide the TextBlock.

WPF How to execute command from Main ViewModel to a child ViewModel in MVVM

I'm using MVVM. I have a tabcontrol and numbers of button in my MainView.
When I click some button it will load child view in tabitem. This child view also having tabcontrol.
Now when I click to some other button the sub child view should be loaded in to childview tabcontrol as tabitem.
What is the best practice for setting up a navigation like this?
I don't want to use EventAggregator. Is there another way to do this?
So how to execute command in child view to load sub child view in child tabcontrol as tabitem from mainview or main window?
You can always use Composite Commands.
Make the button commands composite, and have the child view register to those commands
By the way, is there a specific reason for not wanting to work with the EventAggregator?

which event fires when a listbox finished databinding?

The ASP.NET GridView (and other controls) has the very handy DataBound event, which fires after the GridView finishes databinding. Is there an equivalent event for the Silverlight ListBox (WP7.1)?
My ListBox changes constantly based on user input and I would like to scroll the listbox to a certain item.
As far as I know there is no such event.
But you could use a more generic change listener like ItemsChanged:
listBox1.ItemContainerGenerator.ItemsChanged += new ItemsChangedEventHandler(ItemContainerGenerator_ItemsChanged);
This will also react on normal list changes but you can easily filter these.
The ListBox has a SelectedItem property. Just set it to one of the items, or set the SelectedValue and that will automatically scroll it to make visible.
Here is the MSDN reference of that property: http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditem.aspx

Dynamically Load UserControl using MVVM Light Toolkit

I searched this site and i found 2 Links
how to load wpf usercontrol in MVVM pattern
MVVM-Light: Load UserControl into Window
but still i cant find the answer to my problem and this link
MVVM-Light Locator Pattern and Reusable UserControl
i Didn't Understood.... so here is i am stating my problem which might help others struggling like me ......
I have a MainWindow which has 2 parts one has a TreeView(a
UserControl) and the other Displays different user controls(named DisplayPanel).... just like windows Explorer.
The Display Panel on the Right side will display different user controls on Clicking nodes of tree view.
and my TreeView is Itself a user Control.
How can i make this composite UI Work using MVVM. Also I am planning to use MVVM light Toolkit. Does this have something that can help...
An Example will be great
Thanks... :)
Edit
My TreeView in a UserControl I made a dependency property in the UserControl which catches the selected Item fo the tree view so that i can use this dependency property to populate the required view in the "MainView" ContentControl binding....as you advised me in the comments. Everything is till now
Problem is that i want to display data contained in the the selected item and i cannot set the DataContext of the UserControls(which will be displayed in right hand side) to the selected item as then i will not be able to use my view model for the respective usercontrol for commands and other operations
I tried to solve this too.... i used the Mediator (Messenger) in my TreeViewUserControl view model to send a Message to the Usercontrol's(the one that i need to display) view model . Message will be passed whenever the item is selected in the tree view. and message contains the selected node. I forgot to mention i set the datacontext of the UserControl to its view model so that i could display data
But using this approach the problem is that when the I click a type of node for the first time the data is not populated but if the same type of node is clicked again its populated. What’s happening is that UserControls object is availabe when the the tree item is clicked for the first time and Mediator sends the message. So Mediator is not able to pass the message to the userControl view model.....
I totally do not have ne idea to solve this further.... is my way if displaying user control right or I should do something that else....totally confused.....
You could try defining a DataTemplate for each type in the TreeView's ItemsSource and instead of having a specific UserControl on the right side, just bind to the TreeView's SelectedItem. Alternatively, you could use a DataTemplateSelector.
Edited for OP's Edit
Did you do this?
MainWindow has TreeView whose ItemsSource=Binding MainVM.Items.
MainWindow has ContentControl whose Content=Binding TreeView.SelectedItem.
Somewhere in project, have ResourceDictionary where each possible type in MainVM.Items has a DataTemplate defined?
Which ViewModel (MainVM or ItemVM) are you trying to use and why can't you use it?

WPF TabControl rebinding every time

I am data templating a tab control. Each time I select a tab, the binding of the contents get applied. So for eg, if I have a tree view expanded in tab1 and going to tab2 and coming back has this collapsed. The property binded to ItemsSource is invoked each time I flip the tabs.
learned its all because the visual tree gets recreated again and again as selectd item changes.
Now the qn is, any easy way to fix this. Wil be really helpful.
One way to go is to have an 'IsExpanded' property for a TreeViewItemViewModel and bind to it. Basically your viewmodel will hold the expanded/collapsed state information in your viewmodel.

Resources