Hi
I have a XamTabControl with some TabItemEx items, each TabItemEx has a single different User control on it.
When I select a Tab it creates the User control, the Issue is when I select another a different Tab is it unloads the last User Control.
The real problem is that creating the user control is very expensive so I would like my User Control to remain created once it has be visuallised.
I did read that setting a Name will keep it active (I think this was Dock TabPages), I have set a name but no change.
I commented out all of the code in the User Control (it was a Grid and some heavy graphics) and no change.
Any suggestions ?
thanks
Martin
Actually what you read had to do with xamDockManager and whether it would remove unused SplitPanes/TabGroupPanes. This doesn't relate to xamTabControl. xamtabControl is a derived TabControl. When you change selected tabs in the TabControl, only the content of the selected tab is in the visual tree so as you select different tabs, the wpf framework raises the Unloaded event. This is not something that we control. Assuming that the content of the Tab is your usercontrol then the usercontrol isn't getting recreated. Its just that it wil be unloaded and you will get a loaded again when its brought into view. Maybe you just need to track that you have already initialized the usercontrol and not process the loaded again.
Thanks for the reply, its good to know about the loading/unloading mechanism
I am binding the grid to a object model, one of the cell presenters binds to the content of a cell which itself is an object.
Little example below, "DataVisual" is a User Control that displays the Object, "OffendingUpdate" is binding to the Content, I have a Property change callback so when the 'OffendingUpdate' is changed then calculations are made.
When I change the TabPage and come back again, the DataVisual objects are recreated (breakpoint in constructor) and the "OffendingUpdate" collection is triggered each time.
Displaying the object is a heavy operation as it requires a lot of calculations, I react to property change to build the values and this is where my problem is.
Is this part of the VisualTree unload process? Is it normal user controls or because it is CellValuePresenter in XamGrid?
I have attached a zip with a complete solution.
<UserControl.Resources> <Style x:Key="DataObjectDisplay" TargetType="{x:Type igGrid:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igGrid:CellValuePresenter}"> <Grid> <DataVisual OffendingUpdate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content}"> </DataVisual> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources> <Grid> <igGrid:XamDataGrid DataSource="{Binding Path=Objects}"> <igGrid:XamDataGrid.FieldLayoutSettings> <igGrid:FieldLayoutSettings AutoGenerateFields="False"/> </igGrid:XamDataGrid.FieldLayoutSettings>
<igGrid:XamDataGrid.FieldLayouts> <igGrid:FieldLayout>
<igGrid:FieldLayout.Fields> <igGrid:Field Name="ColorName" Label="ColorName"> <igGrid:Field.Settings> <igGrid:FieldSettings CellValuePresenterStyle="{StaticResource DataObjectDisplay}"/> </igGrid:Field.Settings> </igGrid:Field>
</igGrid:FieldLayout.Fields> </igGrid:FieldLayout> </igGrid:XamDataGrid.FieldLayouts>
</igGrid:XamDataGrid> </Grid>
Yes likely the records/cells are being recycled when the grid is unloaded. Perhaps you can implement a caching mechanism for the calculations or perhaps preloading the records (i.e. setting RecordContainerGenerationMode="PreLoad") will help assuming you don't have lots of records. To look into the matter further, you would need to contact the support group and provide a project that demonstrates the problem.