我有一个由日历+时间选择器组成的WPF用户控件。我打算在弹出窗口中使用这个用户控件,并在文本框焦点上显示弹出窗口。我的问题是我能够正确地显示弹出窗口,但是当用户选择日历中的日期时,弹出窗口就会自动关闭。
在选择特定日期之前,用户基本上没有滚动几年/月/天的选项。如何保持弹出窗口打开,直到文本框失去焦点。
我尝试过StaysOpen + isOpen,但它们都不起作用。
谢谢
我正在发布XAML的一部分,它位于文本框的控制模板中。
<Popup x:Name="DatePickerPopup" IsOpen="False"
Width="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
Height="{TemplateBinding Height}">
<Grid>
<Calendar/>
</Grid>
</Popup>在我的自定义控件中具有bool依赖项属性之后
<Popup x:Name="DatePickerPopup" IsOpen="{Binding IsPopupOpen, RelativeSource={RelativeSource TemplatedParent}}"
Width="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
Height="{TemplateBinding Height}">
<Grid>
<Calendar/>
</Grid>
</Popup>发布于 2013-09-10 12:47:00
我在几个Popup控件中有类似的功能,IsOpen对我来说非常完美.我不知道你拿它干什么。我将其绑定到bool属性,并在希望打开或关闭该属性值时更改该属性值:
<Popup Name="SuggestionsPopup" IsOpen="{Binding IsPopupOpen, RelativeSource={
RelativeSource Mode=FindAncestor, AncestorType={x:Type Controls:
AutoCompleteTextBox}}}" StaysOpen="False" MaxHeight="{Binding MaxPopupHeight,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Controls:
AutoCompleteTextBox}}}" AllowsTransparency="True">发布于 2013-09-11 10:24:39
我已经解决了这个问题。事实上,我下载了WPF工具包的源代码,可以在http://wpftoolkit.codeplex.com/上找到。
它们有一个日期选择器控件,该控件具有相同的场景。
我添加了一个切换按钮,然后将弹出的IsOpen属性绑定到toggle按钮的IsChecked属性。对我来说一切都很顺利。这是演示代码。
<ToggleButton Margin="1" x:Name="_calenderButton"
IsChecked="{Binding IsOpen, RelativeSource={RelativeSource TemplatedParent}}"
IsEnabled="{Binding IsDateTimePickerReadOnlyCallback,
RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource invertBoolConverter}}"
Grid.Column="1">
<Image Height="20" Width="20" Source="pack://application:,,,/Common;component/Images/calender2.jpg"/>
</ToggleButton>
<Popup x:Name="PART_Popup" IsOpen="{Binding IsChecked, ElementName=_calenderButton}" StaysOpen="False">
<Border BorderThickness="1" Padding="3" Background="{StaticResource PopupBackgroundBrush}"
BorderBrush="{StaticResource PopupDarkBorderBrush}">
<StackPanel>
<Calendar x:Name="PART_Calender" BorderThickness="0"/>
<commonControls:TimePicker x:Name="PART_TimePicker"
/>
</StackPanel>
</Border>
</Popup>干杯
https://stackoverflow.com/questions/18718957
复制相似问题