tagridtemplate列下的网格下的datepicker访

tagridtemplate列下的网格下的datepicker访

本文介绍了我如何在我的xaml的datagridtemplate列下的网格下的datepicker访问我的xaml.cs页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The below is my datepicker and I want to add this line of code in my xaml.cs

dtTierValidTo.BlackOutDates.AllDaysinPast();

以下是我在xaml中的日期选择器代码

the below is my datepicker code in xaml

<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中,日期选择器在网格中,即DataGridTemplateColumn

my entire code is like below in xaml, the datepicker is in grid which is 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>


推荐答案

只需创建一个加载日期选择器的事件,如下所示

just create an event of the datepicker loaded like below



in xaml

Name="datepickerName"  Loaded="datepickerName_Loaded"

在xaml.cs中

private void datepickerName_Loaded(object sender, RoutedEventArgs e) {
            DatePicker dp = sender as DatePicker;
            dp.BlackoutDates.AddDatesInPast();
        }

这篇关于我如何在我的xaml的datagridtemplate列下的网格下的datepicker访问我的xaml.cs页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:12