如何在我的xaml中的datagridtemplate列下的网格下访问datepicker到我的xaml.cs页面?我将如何获得这个

时间:2017-07-23 15:09:32

标签: c# wpf xaml datepicker

以下是我的日期选择器,我想在我的xaml.cs中添加这行代码

dtTierValidTo.BlackOutDates.AllDaysinPast();    

以下是我在xaml中的datepicker代码

<DatePicker BorderBrush="LightBlue" BorderThickness="1" 
  Name="dtTierValidTo" Opacity="false" IsEnabled="{Binding CanEdit}"  DisplayDateStart="{Binding TierDealValidFromDate, Mode=TwoWay}"   
SelectedDate="{x:Static sys:DateTime.Now}" DisplayDate="{x:Static sys:DateTime.Now}" 
 Width="120" HorizontalAlignment="Left">
    </DatePicker>

我的整个代码如下面的xaml,datepicker在网格中是DataGridTemplateColumn

<DataGridTemplateColumn Width="140"  Header="Tier Valid To">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding TierDealValidToDateDisplayText}"/>
                                    <!--<TextBlock Text="{Binding TierDealValidToDate}"></TextBlock>-->
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                                            <DataGridTemplateColumn.CellEditingTemplate>
                                                <DataTemplate>
                                                    <Grid>
                                                        <!--<DatePicker BorderBrush="LightBlue" BorderThickness="1" 
                                                                    Name="dtTierValidTo" IsEnabled="{Binding CanEdit}"
                                                                    Text="{Binding TierDealValidToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, TargetNullValue=''}" 
                                                                    DisplayDateStart="{Binding TierDealValidFromDate, Mode=OneWay}"                                                                      
                                                                    DisplayDate="{Binding TierDealValidToDate, Mode=OneWay}" 
                                                                    SelectedDate="{Binding TierDealValidToDate, Mode=OneWay}" 
                                                                    Width="120" 
                                                                    HorizontalAlignment="Left"></DatePicker>-->

                                            <DatePicker BorderBrush="LightBlue" BorderThickness="1" 
                                              Name="dtTierValidTo" Opacity="false" IsEnabled="{Binding CanEdit}"  DisplayDateStart="{Binding TierDealValidFromDate, Mode=TwoWay}"   
                                           SelectedDate="{x:Static sys:DateTime.Now}" DisplayDate="{x:Static sys:DateTime.Now}" 

                                                     Width="120" HorizontalAlignment="Left">
                                            <DatePicker.BlackoutDates>
                                                <!--<CalendarDateRange Start="1/1/1500"  End="{x:Static sys:DateTime.Now.AddDays(-1)}"/>-->
                                                <CalendarDateRange Start="1/1/1500"  End="7/23/2017"/>
                                            </DatePicker.BlackoutDates>
                                        </DatePicker>

                                     <!--DisplayDateStart="{Binding TierDealValidFromDate, Mode=OneWay}"-->                                                                      
                                     <!--SelectedDate="{Binding TierDealValidToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"-->
                                      </Grid>
                                                </DataTemplate>
                                            </DataGridTemplateColumn.CellEditingTemplate>
                                        </DataGridTemplateColumn>

1 个答案:

答案 0 :(得分:0)

只需创建一个如下所示加载的datepicker事件

in xaml

 Array[org.apache.spark.sql.Row] = Array([1,2,3,4,5,6,7,8,9,10...
xaml.cs中的

Name="datepickerName"  Loaded="datepickerName_Loaded"