Windows Desktop App: Prism Default Page

Mon, Mar 20, 2017 2-minute read

This will be short because it’s mostly a note to myself. I just got started doing WPF applications using, Prism.

The most useful part I’ve used so far has been this video:

What I what to cover specifically in this post: handling the default view/window of an applicaiton. If you followed the video from the link posted above, you’ll have an application that can do navigation and how data from other Views with a backed ViewModel. The issue currently is a required click to start the first view. I’ve found a way to get a “default” view in place from this stackoverflow post:

Here is the code from stackoverflow:

        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction Command="{Binding LoadedCommand}" CommandParameter="{Binding Message, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type view:TestView}}}" />
            <TextBlock Text="{Binding Message, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type view:TestView}}}"/>
            <TextBlock Text="{Binding Message}"/>

The most important part here is the use of the i:Interaction part. It allows you to call your navigation command from that trigger. So the code I’ve used in my application to default to the login view is:

    <i:EventTrigger EventName="Loaded">
        <i:InvokeCommandAction Command="{Binding NavigateCommand}" CommandParameter="Login"></i:InvokeCommandAction>

With that I’ve been able to get the default login View and ViewModel to load and start handling the application.