Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
755
How to get datatemplate object
posted

Hi

I defined in the tabcontrol datagrid as item, you can see in the following code snippet.

  <Grid Margin="5,0,5,0">
        <igWindows:XamTabControl Name="_xamTabControl"
             ItemsSource="{Binding AutoLogins}"
             Theme="Metro"
             AllowTabClosing="False"
             TabItemCloseButtonVisibility="WhenSelectedOrHotTracked"
             SelectionChanged="_xamTabControl_OnSelectionChanged">
            <igWindows:XamTabControl.ItemContainerStyle>
                <Style TargetType="{x:Type igWindows:TabItemEx}" BasedOn="{x:Static igThemes:PrimitivesMetro.TabItemEx}">
                    <Setter Property="Header" Value="{Binding Server}" />
                </Style>
            </igWindows:XamTabControl.ItemContainerStyle>
            <igWindows:XamTabControl.ContentTemplate>
                <DataTemplate>
                    <igDp:XamDataGrid DataSource="{Binding Logins}" IsGroupByAreaExpanded="False"
                                      GroupByAreaLocation="None" GroupByAreaMode="DefaultFieldLayoutOnly"
                                      RecordDeactivating="DataPresenterBase_OnRecordActivated"
                                      LostFocus="_dataGrid_OnLostFocus">
                        <igDp:XamDataGrid.FieldLayoutSettings>
                            <igDp:FieldLayoutSettings AddNewRecordLocation="OnBottom" AllowAddNew="True" AllowDelete="True" />
                        </igDp:XamDataGrid.FieldLayoutSettings>
                        <igDp:XamDataGrid.FieldSettings>
                            <igDp:FieldSettings AllowResize="False" LabelWidth="200" LabelTextAlignment="Center" />
                        </igDp:XamDataGrid.FieldSettings>
                    </igDp:XamDataGrid>
                </DataTemplate>
            </igWindows:XamTabControl.ContentTemplate>
        </igWindows:XamTabControl>
    </Grid>

My question is, how can I get the XamDataGrid object within _xamTabControl_OnSelectionChanged event. What I want to do is to validate, if any datarecord in the xamdatagrid is empty.

Thanks

Parents
  • 34510
    Offline posted

    Hi Jean-Pascal,

    You should perform your validation directly on the data source rather than going through the XamDataGrid.  Since you are using the ItemsSource of the tab control, each tab item's DataContext should be an instance of the items in your AutoLogins collection.  From there you can get the Logins collection and validate the data inside.

    If you must get the XamDataGrid from code, you can use the Infragistics.Windows.Utilities class to get the child UI elements of the TabItemEx element.  GetDescendentFromType should do the trick.

Reply Children