【问题标题】:Unable to get the popup open in WPF无法在 WPF 中打开弹出窗口
【发布时间】: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 事件,导致弹出窗口立即关闭。

标签: wpf vb.net telerik


【解决方案1】:

事实证明,保持开放的属性会导致问题。我将其设置为 true 并且它起作用了。现在这两个事件都按预期触发。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多