我正在创建一个新的日历控件。我已将所选日期设置为按钮文本。我需要在选择日期时关闭我的日历。
<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代码。等待你的宝贵帮助。提前谢谢。
答案 0 :(得分:1)
您必须使用Blend Behaviors
进行纯XAML方法。
的xmlns:ⅰ= “CLR-名称空间:System.Windows.Interactivity;装配= System.Windows.Interactivity” 的xmlns:IC = “CLR-名称空间:Microsoft.Expression.Interactivity.Core;装配= 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>