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

순수 XAML 방식에 Blend Behaviors을 사용해야합니다.

Blend 3 SDK, Blend 4 SDK을 다운로드하십시오.

의 xmlns : I = "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

해결책 주셔서 감사합니다. 패키지 관리자 콘솔에서 System.Windows.Interactivity.dll을 설치 한 후 제대로 작동합니다. – user3065219

관련 문제