简体   繁体   English

c#wpf)如何故意打开Datepicker的日历向上?

[英]c# wpf) how to open calendar of Datepicker to upside intentionally?

What I want to know is very simple. 我想知道的很简单。 If I click the DatePicker, the calendar is opened downside and cover other things not to be seen. 如果单击DatePicker,则日历将打开,并覆盖其他不可见的内容。

I tried to search on Properties and internet, stackoverflow but failed to find a solution. 我尝试在“属性”和Internet,stackoverflow上进行搜索,但是找不到解决方案。 Is there a simple, easy solution to solve this? 是否有简单,简单的解决方案来解决此问题?

I always highly appreciate excellent people of stackoverflow. 我一直非常感谢Stackoverflow的优秀人才。 Thank you so much ! 非常感谢 !

You'll need to adjust the control template of the DatePicker control to accomplish this. 您需要调整DatePicker控件的控件模板来完成此操作。

First get a copy of the original control template. 首先获得原始控件模板的副本。 You'll start from the original template and only edit the things you want to change. 您将从原始模板开始,仅编辑要更改的内容。 The easiest way to do this is with Blend. 最简单的方法是使用Blend。

  • Open your project in Blend 在Blend中打开您的项目
  • Right click the DatePicker control 右键单击DatePicker控件
  • Click Edit Template, then Edit a copy 单击编辑模板,然后编辑副本
  • Create a new resource dictionary (new... at the bottom) and check the radio button to save the template in it. 创建一个新的资源字典(位于底部的new ...),然后选中单选按钮以将模板保存在其中。

Now open the new file you have just created and edit the template as follows. 现在打开刚刚创建的新文件,并按如下所示编辑模板。 Change this: 更改此:

<Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>

To this: 对此:

<Popup x:Name="PART_Popup" AllowsTransparency="True" Placement="Top" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>

Give the template a good name: 给模板起一个好名字:

x:key="MyCustomDatePicker"

Then update your DatePicker as follows: 然后,如下更新您的DatePicker:

<DatePicker
    ...
    Template="{StaticResource MyCustomDatePicker}"
    ... />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM