2016-09-28 118 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