Search code examples
c#wpfdatepickerinfragisticsxamgrid

How to access date picker control within xamGrid in Wpf?


Following is my XamGrid and I have used template column which contain date picker control, question is how to access date picker control so that I can apply my logic?


    <ig:XamGrid x:Name="MyGrid" AutoGenerateColumns="False"  KeyboardNavigation="AllLayouts" ActiveCellChanged="MyGrid_ActiveCellChanged" >
        <ig:XamGrid.Columns>
            <ig:TextColumn Key="ID" />
            <ig:TextColumn Key="Name"/>
            <!--<ig:DateColumn Key="Birthday" SelectedDateFormat="Short" HeaderText="Date of birth"></ig:DateColumn>-->
            <ig:TemplateColumn Key="Birthday">
                <ig:TemplateColumn.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock>Date of birth</TextBlock>
                    </DataTemplate>
                </ig:TemplateColumn.HeaderTemplate>
                <ig:TemplateColumn.ItemTemplate>
                    <DataTemplate>
                        <DatePicker SelectedDateFormat="Short" Text="{Binding Birthday}" Name="datepicker1"></DatePicker>
                    </DataTemplate>
                </ig:TemplateColumn.ItemTemplate>
            </ig:TemplateColumn>
            <!--<ig:CheckBoxColumn Key="Graduate">
                <ig:CheckBoxColumn.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="Graduation completed"></TextBlock>
                    </DataTemplate>
                </ig:CheckBoxColumn.HeaderTemplate>
            </ig:CheckBoxColumn>-->
            <ig:TextColumn Key="Graduate" HeaderText="Graduation completed" CellStyle="{StaticResource CellStyle}" />
            <!--<ig:CheckBoxColumn Key="Masters">
                <ig:CheckBoxColumn.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="Masters completed"></TextBlock>
                    </DataTemplate>
                </ig:CheckBoxColumn.HeaderTemplate>
            </ig:CheckBoxColumn>-->
            <ig:TextColumn Key="Masters" HeaderText="Masters completed" CellStyle="{StaticResource mastercell}" />
            <ig:ComboBoxColumn Key="Gender" HeaderText="Gender"></ig:ComboBoxColumn>
            <ig:TemplateColumn Key="Edit" HorizontalContentAlignment="Center">
                <ig:TemplateColumn.ItemTemplate>
                    <DataTemplate>
                        <Button Content="Edit" Height="25" Width="50" Click="Button_Click"></Button>
                    </DataTemplate>
                </ig:TemplateColumn.ItemTemplate>
            </ig:TemplateColumn>
        </ig:XamGrid.Columns>
        <ig:XamGrid.SelectionSettings>
            <ig:SelectionSettings CellClickAction="SelectCell" ColumnSelection="Single" CellSelection="Single" RowSelection="Single"></ig:SelectionSettings>
        </ig:XamGrid.SelectionSettings>
        <ig:XamGrid.PagerSettings>
            <ig:PagerSettings AllowPaging="Top" PageSize="5"></ig:PagerSettings>
        </ig:XamGrid.PagerSettings>
        <ig:XamGrid.FixedColumnSettings>
            <ig:FixedColumnSettings  AllowFixedColumns="Both"></ig:FixedColumnSettings>
        </ig:XamGrid.FixedColumnSettings>
        <ig:XamGrid.EditingSettings>
            <ig:EditingSettings AllowEditing="Cell"/>
        </ig:XamGrid.EditingSettings>
    </ig:XamGrid>

How could access datepicker so that i can perform validation on it.


Solution

  • Your grid is part of some user control/window right?

    <DatePicker SelectedDateFormat="Short" Text="{Binding Birthday}" Name="datepicker1"
    Loaded="YourEvent"></DatePicker>
    

    Just create event on DatePicker Loaded then in event

    private void YourEvent(object sender, System.Windows.RoutedEventArgs e)
    {
      var datePicker =  sender as DatePicker;
      //then apply your logic.
    }