WPF的DataGrid日历不响应鼠标单击. [英] DataGrid Calendar of WPF is not responding to Mouse click.

查看:112
本文介绍了WPF的DataGrid日历不响应鼠标单击.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我在WPF中有一个DataGrid,它绑定到MS Access数据库.其列之一是DateTime类型.并且其标题名称是"DOB".现在,我要将日历嵌入到DataGrid单元中.这样我就可以通过单击适当的单元格来输入日期 我能够显示日历,但不幸的是,日历始终显示2012,并且它不响应鼠标单击.即,按预期方式,当我们单击DataGrid中的一个单元格时,将显示一个弹出的日历.既有前后箭头, 单击此箭头时,它应该转到下一年或上一年.类似地,当我们单击一个单元格时,该特定的Date应该出现在Datagrid单元格中.这没有发生.确切的说,我正在获取"Dead Calender".我正在提供代码 获取资源 字典和mainwindow.xaml分别

I have a DataGrid in WPF.which is binded to a MS Access DataBase . one of its column is DateTime type. and its heading name is "DOB". now I want to embeds the calender in my DataGrid cell. so that I can enter the Date by clicking on appropriate cells in the Calender.I was able to display the calender but unfortunately the calender always shows 2012 and it do not respond the mouse click. ie as expected when we click a cell in the DataGrid a pop up calender will appear. which have both front and back arrows, while clicking this arrow it should go to next or previous year. similarly when we click on a cell that particular Date should appear in the Datagrid cell. this is not happening . exactly I am getting a Dead Calender.I am giving the code  for resource dictionary and mainwindow.xaml respectively

 <Style TargetType="{x:Type dg:Calendar}" x:Key="CalenderControlTemplate">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="dg:Calendar" >
                    <dg:CalendarItem Name="myCalendarItem" 
                                 Background="Yellow" 
                                 BorderBrush="Black"
                                 BorderThickness="1"
                                 VerticalAlignment="Center" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <DataTemplate x:Key="EffDateDateTimePickerControl">
       
        <TextBlock Text="{Binding DOB, StringFormat=d}"  />
    </DataTemplate>

    <DataTemplate x:Key="addrEffDate">
        <dg:DatePicker x:Name="dpEffDate" Text="{Binding Path=effectiveDate,Mode=TwoWay}"
                  
     
                     SelectedDate ="{Binding DOB}" SelectedDateFormat="Short"
                   
                   CalendarStyle="{DynamicResource CalenderControlTemplate}" />
    </DataTemplate>


for mainwindow.xaml

 <dg:DataGridTemplateColumn CellEditingTemplate ="{StaticResource addrEffDate}" CellTemplate="{StaticResource  EffDateDateTimePickerControl}"  Header="Effective Date">
               
            </dg:DataGridTemplateColumn>
         
            
        </dg:DataGrid.Columns>

请有人帮我解决这个问题

please somebody help me resolve this

 

推荐答案

尝试连接PreviewClick事件处理程序以查看是否适合您.
Try wiring up a PreviewClick event handler to see if that works for you.


这篇关于WPF的DataGrid日历不响应鼠标单击.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆