How to get this XAML shorter?

Topics: Prism v4 - Silverlight 4
Oct 19, 2011 at 2:17 AM

Consider bunch of XAML below. I have to paste it on each View. Is there any way to make it DRY? I need Dialogs on all my Views, but I don't want to include this bunch of each View.

 

<i:Interaction.Triggers>
                <prism:InteractionRequestTrigger SourceObject="{Binding NotificationInteractionRequest}">
                    <interactionRequest:InteractionDialogAction>
                        <interactionRequest:InteractionDialogAction.Dialog>
                            <interactionRequest:NotificationLocalModalInteractionDialog />
                        </interactionRequest:InteractionDialogAction.Dialog>
                        <interactionRequest:InteractionDialogAction.ContentTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding}" TextWrapping="Wrap" FontSize="14" VerticalAlignment="Center" />
                                </StackPanel>
                            </DataTemplate>
                        </interactionRequest:InteractionDialogAction.ContentTemplate>
                    </interactionRequest:InteractionDialogAction>
                </prism:InteractionRequestTrigger>
                <prism:InteractionRequestTrigger SourceObject="{Binding ConfirmationInteractionRequest}">
                    <interactionRequest:InteractionDialogAction>
                        <interactionRequest:InteractionDialogAction.Dialog>
                            <interactionRequest:ConfirmationLocalModalInteractionDialog />
                        </interactionRequest:InteractionDialogAction.Dialog>
                        <interactionRequest:InteractionDialogAction.ContentTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding}" TextWrapping="Wrap" FontSize="14" VerticalAlignment="Center" />
                                </StackPanel>
                            </DataTemplate>
                        </interactionRequest:InteractionDialogAction.ContentTemplate>
                    </interactionRequest:InteractionDialogAction>
                </prism:InteractionRequestTrigger>
            </i:Interaction.Triggers>

Developer
Oct 19, 2011 at 6:15 PM

Hi,

As a possible approach you could try to store this XAML code in a ResourceDictionary as resource.

Also, you could make this XAML code shorter by storing the DataTemplates used for the ContentTemplates of the dialogs as resources.

You might find the following work items useful as they contain different approaches to use ResourceDictionaries in prism and informs of different problems that might appear when doing so:

 

I hope you find it useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini