2014-09-25 60 views
0

以下是我的XamGrid,我已經使用了包含日期選擇器控件的模板列,問題是如何訪問日期選擇器控件,以便我可以應用我的邏輯?如何在Wpf中訪問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> 

怎麼能訪問日期選擇器,這樣我可以在其上進行驗證。

+0

請幫助我,我初學WPF – IAmDineshL 2014-09-25 05:55:08

回答

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. 
} 
+0

你幾乎是正確的,但只是很小的事情是你必須認購LostFocus事件和它的工作原理現在給我。感謝幫助.... – IAmDineshL 2014-09-25 07:18:11

相關問題