This is a migrated thread and some comments may be shown as answers.

Keep columns order when GridView instance is dynamically removed from visual tree and later readded

1 Answer 30 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 16 Mar 2011, 10:26 AM
Hi

We use Silverlight 4 in combination with RIA services. In our application we dynamically place the GridView instance to different ContentControls.
simplified Example:

UI
<Grid
<Grid.ColumnDefinitions
<ColumnDefinition Width="*" /> 
<ColumnDefinition Width="*"/>
 </Grid.ColumnDefinitions
<ContentControl Content="{Binding UserControlLeft}" ></ContentControl
<ContentControl Content="{Binding UserControlRight}" Grid.Column="1"><ContentControl
</Grid>
 

 

 

 

ViewModel

public class BaseStructureModel : ViewModelBase {
   
public UserControl UserControlLeft {get;set;}  // for the sake of simplicitly INotifiedPropertyChanged stuff left out
 public UserControl UserControlRight {get;set;}
...}


CODE to assign GridView to different controls
var gridViewInstance = UserControlLeft as GridView;
UserControlLeft = null;
UserControlRight = gridViewInstance;  // column order changes the the user applied arre lost :-(

This works mostly but unfortunately, when the user changes the columns order, it will be lost when the gridview instance is applied to another content control. Furthermore, filter values entered by the user are also lost (or better will no longer work properly).

What can we do about it? Is there a possibility to ensure that settings the user applied (such as column order and filtering) are preserved whenn assigning the gridview control to another content control

Thanks for your help

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
answered on 16 Mar 2011, 11:13 AM
Hi

I have found the solution. It actually had nothing to do with the grid.  As I am a silverlight (and wpf) newby, i didnt know that the user control loaded event is triggered when the control is reassigned to a content control. (Now when a think of it, it seems logical). However, in the UserControl_Loaded event, we executed code, that caused the grid to reset some settings. Thats all.

Greetings
Tags
GridView
Asked by
Dan
Top achievements
Rank 1
Answers by
Dan
Top achievements
Rank 1
Share this question
or