2016-09-28 125 views
0

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

<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代码。等待你的宝贵帮助。提前致谢。

回答

1

您必须使用Blend Behaviors作为纯粹的XAML方法。

下载Blend 3 SDKBlend 4 SDK

的xmlns:ⅰ= “CLR-名称空间:System.Windows.Interactivity;装配= System.Windows.Interactivity” 的xmlns:IC =“CLR-名称空间:Microsoft.Expression.Interactivity.Core;装配=微软.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> 
+0

我正在使用.net框架4.5。我无法安装System.Windows.Interactivity.dll。我们有任何支持4.5的版本吗? – user3065219

+1

请参阅更新代码,我已发布Blend SDK 4下载链接。 – AnjumSKhan

+0

感谢您的解决方案。从Package Manager Console安装System.Windows.Interactivity.dll后,它工作正常。 – user3065219