如何在Wpf中访问xamGrid中的日期选择器控件?

时间:2014-09-25 05:13:51

标签: c# wpf datepicker infragistics xamgrid

  

以下是我的XamGrid并且我使用了包含日期选择器控件的模板列,问题是如何访问日期选择器控件以便我可以应用我的逻辑?


    <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>

如何访问datepicker以便我可以对其进行验证。

1 个答案:

答案 0 :(得分:0)

您的网格是某个用户控件/窗口的一部分吗?

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

只需在DatePicker上创建事件,然后在事件

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