【发布时间】:2015-06-19 11:22:00
【问题描述】:
因此,我正在尝试创建一个日历弹出窗口,该弹出窗口会在文本框获得焦点后立即打开。下面是我正在使用的代码。
<TextBox x:Name="CalendarTextBox" BorderBrush="#CCCCCCCC" Foreground="#FF777777" HorizontalAlignment="Right" Width="305" Height="30" VerticalContentAlignment="Center" Panel.ZIndex="10" Margin="0,10,10,0" VerticalAlignment="Top" SelectionBrush="#FF0081A7" BorderThickness="2" GotFocus="CalendarTextBox_GotFocus" LostFocus="CalendarTextBox_LostFocus"/>
<Popup x:Name="PopUpCalendar" PlacementTarget="{Binding ElementName=CalendarTextBox}" StaysOpen="False" Width="305" Height="305" Panel.ZIndex="200">
<telerik:RadCalendar HorizontalAlignment="Left" VerticalAlignment="Bottom" Orientation="Vertical" AreWeekNamesVisible="False" Width="305" Height="305">
<telerik:StyleManager.Theme>
<telerik:Windows8Theme/>
</telerik:StyleManager.Theme>
</telerik:RadCalendar>
</Popup>
后面的代码:
Private Sub CalendarTextBox_GotFocus(sender As Object, e As RoutedEventArgs)
PopUpCalendar.IsOpen = True
End Sub
Private Sub CalendarTextBox_LostFocus(sender As Object, e As RoutedEventArgs)
PopUpCalendar.IsOpen = False
End Sub
类似的代码适用于页面中的其他弹出窗口。但不知何故,日历根本不显示。奇怪的是,代码被正确执行,但在那之后,页面上没有日历弹出窗口。我无法弄清楚我错过了什么。我什至将 Zindex 增加到了一个非常高的数字。
【问题讨论】:
-
当您说“代码执行正确”时,您的意思是
Popup打开,但RadCalendar不可见?或者Popup甚至没有打开? -
弹出窗口未打开。我在代码中放了一个断点,代码就跑起来了。
-
您能否在
CalendarTextBox_LostFocus中添加一个断点,看看是否在弹出窗口打开后立即运行?如果弹出窗口在打开时获得焦点,则可能会触发LostFocus事件,导致弹出窗口立即关闭。