2016-09-28 14 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 framework 4.5を使用しています。 System.Windows.Interactivity.dllをインストールできません。 4.5でサポートされているバージョンはありますか? – user3065219

+1

更新されたコードをご覧ください。私はBlend SDK 4のダウンロードリンクを投稿しました。 – AnjumSKhan

+0

あなたの解決に感謝します。パッケージマネージャコンソールからSystem.Windows.Interactivity.dllをインストールした後で正常に動作しています。 – user3065219

関連する問題