Caliburn.Micro ShowPopup - set focus
I'm trying to use Caliburn.Micro (for my first WPF MVVM project) and I'm struggling with getting the WindowManager.ShowPopup method to set focus to the popup screen. Is this possible? The sample HelloWindowManager from Caliburn doesn't do it either, and the documentation is pretty light.
Answers
Ultimately, I was unable to get the ShowPopup method to work as I wanted.
What I did instead was use ShowWindow, and then used the EventAggregator to publish an event when I was showing the window. In the ViewModel for the called View, I subscribed to that event, and set a property on the ViewModel to true (named KeywordEntryActive in this example).
I then use a Style on the Grid that uses a DataTrigger bound to that property to call the FocusManager.FocusedElement method in the View.
<Grid.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding KeywordEntryActive}" Value="True"> <Setter Property="FocusManager.FocusedElement" Value="{Binding ElementName=Command}" /> </DataTrigger> </Style.Triggers> </Style> </Grid.Style>
It seemed less straightforward than I hoped, but I was able to accomplish what I was looking for without sacrificing the separation of ViewModel and View, so I'm satisfied with it at this point. There's been a bit of a learning curve with Caliburn.Micro but so far I've been able to overcome the snags I've run into, and I'm continuing down this path.