I am in a situation where i have a grid which is binded using Mvvm approach in left side of GUI.Now in my GUI just right to it i have TabControl which has 3 TabItems.
Suppose that there are 2 grids (each representing two different objects data) my GUI must work like if i click a grid it must update the UIElements Corresponding to that grid object in a TabItem which is called as "Preview Parameters". And if i click another grid it will render another UIelements of the clicked object.
What i have done yet?
I have ProgramVersionGrid.xaml (where i have done bindng of grid like this):
<data:DataGridGrid.ColumnSpan="2"Grid.Row="1"x:Name="gridVersions"ItemsSource="{Binding ProgramVersion}"IsReadOnly="True"AutoGenerateColumns="False"SelectedItem="{Binding SelectedVersion, Mode=TwoWay}">
Here you can see as i click the DataGrid it's object is invoked and SelectedVersion will contain all the data to be rendered in its viewmodel class. In it's viewmodel class i do like this:
publicclassProgramVersionViewModel:GenericViewModel//GenericViewModel contains INotification{privateProgramVersion selectedVersion;publicProgramVersionSelectedVersion{get{return selectedVersion;}set{
selectedVersion = value;//here i can have the data of version clicked here in SelectedVersion and i can access by doing this: selectedVersion.dataOnPropertyChanged("SelectedVersion");}}}
My Tab control class is like this:
<Grid><tbcontrol:UIeLementRenderName="UIeLementRender"/><controls:TabControlGrid.Row="0"BorderThickness="0"Background="White"TabStripPlacement="Right">
//There are 3 tabItems(each having usercontrol) and i am just showing you the one that renders UI elements
<controls:TabItemx:Name="TabItem3"Height="140"Width="40"FontSize="13"><controls:TabItem.Header><toolkit:LayoutTransformer><TextBlockText="preview Parameters"/><toolkit:LayoutTransformer.LayoutTransform><RotateTransformAngle="90"></RotateTransform></toolkit:LayoutTransformer.LayoutTransform></toolkit:LayoutTransformer></controls:TabItem.Header><TabItems: **UIeLementRender** x:Name="ucTab3Data"/> //UIeLementRender.xaml contains teh usercontrol for rendering UIElements</controls:TabItem></controls:TabControl></Grid>
where this UIeLementRender.xaml is :
<Gridx:Name="LayoutRoot"Background="White"><ContentControlName="UiElementPreview"Content="{Binding Preview}"Grid.Row="1"/></Grid>
I have used ContentControl because on clicking the Grid will create a Grid containign UIelemnts and that is supposed to be rendered on this TabItem, so ContentControl is Container for that grid containing UI elemnts.
And its viewModel is:
publicclass uiElementRendererViewModel :GenericViewModel{privateGrid preview;publicGridPreview{get{return preview;}set{ preview = value;OnPropertyChanged("Preview");}}}
Whatr is the problem ?
The problem is i have to manage this situation in such a way that when i click first grid (which is Mvvm approach binded) it will render the UIelement in TabItem and when i will clicksecodn grid it will click the second grid it will render the UIelemnts corresponding to second grid in the Tabitem again. How to achieve this ?
(Inshort if i say, How should i change my ProgramVersionGridViewmodel.cs class so that i will be able to pass the selectedVerion in uiElementRendererViewModel.cs and can update the UIelemnt contained in Selectedversion in TabItems on dynamic
click to DataGrids) ? (this selectedVersion is of type ProgramVersion which on doing this in uiElementRendererViewModel.cs will return a grid containing Uielements Grid Preview = ReturnGridContainingUIElements(SelectedVersion); and this Preview
(grid) is to be updated on TabItem ) and how to do something like this "uiElementRenderer.DataContext = new uiElementRendererViewModel(SelectedVersion);
Inside theSet()
of SelectedVersion
in ProgramVersionViewModel.cs
class so taht each time i selectVersion on DataGrid click i will be able to update the UIelement in TabItem "? because uiElementRenderer
has no access there.
Note :Please note that it would be a dynamic process as first i run program then i will click the grid then i clcik TabItem (the third one which corresponds to UIelement) then it render there UIelements. On switching to another DataGrid will do the same procedure.