InteractionRequests: ToastPopupAction

Topics: Prism v4 - Silverlight 4
Jun 29, 2011 at 3:39 PM

Hi,

[Windows Phone 7 app]

I am trying to figure out how to use Interaction Requests with a Toast notifications, so far (at best) I have received an InvalidCastException when I execute the _confirmSyncInteraction.Raise event - here is my code:

VIEWMODEL:

      // raise the sync completed trigger
            _confirmSyncInteractionRequest.Raise(
                new Notification() { Title = "Sync Complete", Content = "gfsgfdsgfdsgdfd"},
                action => new ToastPopupAction() { PopupElementName = "SyncPopup", IsEnabled = true});

and with a corresponding trigger in the xaml:
VIEW:
    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Name="SyncPopup">
            <Grid MinWidth="250" MinHeight="100">
                <TextBlock TextWrapping="Wrap" Grid.Row="0" Text="fdsgfdsgfsdgfd"/>
            </Grid>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>
    
    <i:Interaction.Triggers>
        <prism:InteractionRequestTrigger SourceObject="{Binding ConfirmSyncInteractionRequest}">
            <prism:ToastPopupAction PopupElementName="SyncPopup" IsEnabled="True"/>
        </prism:InteractionRequestTrigger>
    </i:Interaction.Triggers>

Any help very much appreciate, Mark



        
            
                
            
        
    
    
    
        
            
        
    

 

Developer
Jun 29, 2011 at 5:45 PM

Hi Mark,

It would be helpful if you could provide us with a repro sample that demonstrates this problem, so that we can help you find the cause for it.

Thanks,

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Jun 29, 2011 at 6:11 PM

Hi,

 

Have uploaded a test solution here:

Mutable.Sync.zip

Jul 6, 2011 at 5:42 PM

Hi Mark,

We’ve examined your sample and found that the reason of an InvalidCastException being thrown is that the ToastPopUpAction is trying to cast the popup element you’ve defined in your xaml (in your case SyncPopup which is a DataTemplate) to a PopUp control.

To avoid this problem, we’ve changed your DataTemplate into a PopUp element and placed it inside your Grid (that is to say, we didn’t place it inside the application resources). The xaml looks like this:

<Grid x:Name="LayoutRoot" Background="Transparent" d:DataContext="{Binding Items[0]}">
       
       <Grid.RowDefinitions>
           <RowDefinition Height="Auto"/>
           <RowDefinition Height="*"/>
       </Grid.RowDefinitions>
 
<!—A PopUp control must be used in order to place the toast notification-->
       <Popup x:Name="SyncPopup">
           <Grid MinWidth="250" MinHeight="100">
               <TextBlock TextWrapping="Wrap" Grid.Row="0" Text="fsdgfsdgfdsgfs"/>
           </Grid>
       </Popup>

 

After applying those changes, we tested the sample and found that it correctly displayed the toast notification.

I hope you find this information useful.

Thanks,

Miguel Bronzovic
http://blogs.southworks.net/mbronzovic