【问题标题】:Closing calender when a date is selected选择日期时关闭日历
【发布时间】:2016-09-28 22:16:14
【问题描述】:

我正在创建一个新的日历控件。我已将所选日期设置为按钮文本。选择日期后,我需要关闭日历。

<Window x:Class="DemoApp2.Views.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
     <Window.Resources>
     </Window.Resources>
  <Grid>
      <ToggleButton x:Name="btn" Content="{Binding SelectedDate, ElementName=CalendarControl}" Background="Red" Margin="50,103,55,130">
      </ToggleButton>
      <Popup IsOpen="{Binding ElementName=btn, Path=IsChecked}" StaysOpen="False" PopupAnimation="Scroll" PlacementRectangle="50,53,50,50">
         <Calendar x:Name="CalendarControl"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
         </Calendar>
       </Popup>
   </Grid>
</Window>

我更喜欢 xaml 代码。等待您的宝贵帮助。提前致谢。

【问题讨论】:

    标签: wpf xaml calendar


    【解决方案1】:

    对于纯 XAML 方法,您必须使用 Blend Behaviors

    下载Blend 3 SDKBlend 4 SDK

    xmlns:i="clr-命名空间:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"

    <ToggleButton x:Name="btn" Content="{Binding SelectedDate, ElementName=CalendarControl}" Background="Red" Margin="50,103,55,130"/>
    
    <Popup x:Name="Popup1" IsOpen="{Binding IsChecked, ElementName=btn, Mode=TwoWay}" StaysOpen="False" PopupAnimation="Scroll" PlacementRectangle="50,53,50,50">
        <Calendar x:Name="CalendarControl"               
                HorizontalAlignment="Center"
                VerticalAlignment="Center">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectedDatesChanged">
                    <ic:ChangePropertyAction TargetName="btn" PropertyName="IsChecked" Value="False"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Calendar>
    </Popup>
    

    【讨论】:

    • 我正在使用 .net 框架 4.5。我无法安装 System.Windows.Interactivity.dll。我们有支持 4.5 的版本吗?
    • 请查看更新代码,我已经发布了 Blend SDK 4 下载链接。
    • 感谢您的解决方案。从包管理器控制台安装 System.Windows.Interactivity.dll 后它工作正常。
    猜你喜欢
    • 1970-01-01
    • 2019-04-23
    • 2019-09-28
    • 1970-01-01
    • 1970-01-01
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多