I'm developing a really simple control which is basically just a hyperlink that displays DatePicker in Popup when clicked (all created in code, but I think it doesn't matter). XAML:
<Window x:Class="WpfPopupTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"><Grid Name="grid"><TextBlock VerticalAlignment="Center" Name="outerTextBlock" /></Grid></Window>and the code-behind for it:
public partial class MainWindow : Window {
private DatePicker datePicker = new DatePicker();
private Popup popup = new Popup();
private Hyperlink hyperlink = new Hyperlink();
public MainWindow() {
InitializeComponent();
popup.Child = datePicker;
popup.Placement = PlacementMode.Relative;
popup.PlacementTarget = outerTextBlock;
popup.StaysOpen = false;
hyperlink.Click += (o, e) => popup.IsOpen = true;
TextBlock innerTextBlock = new TextBlock { Text = "Click" };
datePicker.SelectedDateChanged += (o, e) => {
popup.IsOpen = false;
innerTextBlock.Text = datePicker.SelectedDate.Value.ToLongDateString();
};
hyperlink.Inlines.Add(innerTextBlock);
outerTextBlock.Inlines.Add(hyperlink);
}
}Consider the following scenario:
- click the hyperlink, popup is open
- click the calendar
- pick date
- popup is closed, selected date is shown as hyperlink text
- the hyperlink becomes non-clickable, the cursor no longer changes to "hand" when the mouse pointer is over it.
But if I move the pointer out of the bounds of this window and return it back or maximize/minimize it or move the window any other way everything becomes fine again. Looks like some kind of call to UpdateLayout is not occuring for my case. Am i missing something?