newbie Modal window

Topics: Prism v2 - Silverlight 4
Dec 14, 2010 at 4:49 PM

I  have a couple of modules. Each module has a chart control. I need to be able to open up a modal window control when the user clicks on a single bar on the chart populating a grid in the window with some data pertinent to the bar clicked. How do I go about this. Any direction on the code and structure would be helpful.

Thanks.

Developer
Dec 14, 2010 at 6:29 PM

Hi,

You might find the following thread useful to your purpose, as shows a similar requirement:

Simulate Modal Window

Additionally, you could make use of this sample, in which there is a region defined inside a Silverlight Child Window.

I hope you find this helpful.

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

Dec 14, 2010 at 9:20 PM

Can I instead create a module with the modal control and subscribe to events published by other modules and show the modal window? Has anybody tried this approach. My concern here is how to show and hide the region/modal window.

Dec 15, 2010 at 5:14 PM

Hi,

Prism provides an event mechanism that enables communications between loosely coupled components in your applications. You could fulfill this scenario using Event Aggregator which allows communication via events with components that do not have references to each other.

You can read more about this in Chapter 9: Communicating Between Loosely Coupled Components, Event Aggregator´s Section.

As Guido mentioned in the Simulate Modal Window´s thread, you can use Stock Trader Reference Implementation to achieve your scenario of modal window.

Thanks,

 

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

 

Dec 17, 2010 at 2:27 PM

I am having trouble understanding what all pieces I would need from the Stocktrader RI implementation to get the modal window working in my application. At this time from the behaviors folder I have the DialogActivationBehavior.cs, IWindow.cs, PopupDialogActivationBehavior.cs, PopupWrapper.cs, RegionPopupBehaviors.cs included in my infrastructure project. and added these 2 lines of code in the shell.xaml changing the namespaces to my application namespaces.

xmlns:infBehaviors="clr-namespace:MyApplication.Infrastructure.Behaviors;assembly=MyApplication.Infrastructure"    

infBehaviors:RegionPopupBehaviors.CreatePopupRegionWithName="SecondaryRegion"

 

What other pieces do I need to open the pop up on a button click from one of my views.

Thanks.

Dec 17, 2010 at 6:44 PM
Edited Dec 17, 2010 at 6:48 PM

that is all that is necessary, then using RegionManager to activate/deactivate (open/close) the "popup", once you have added the views to the SecondaryRegion in the RegionManager.  Also might considering running this region scoped for the reason of making sure that you don't get a reused viewmodel.  I have found that the view/viewmodel doesn't get collected or properly disposed even with lifetime of the window attributed to false for some reason.

Dec 17, 2010 at 7:11 PM

Hi,

As mentioned by Morgan, with the components that you've mentioned it is possible to complete your popup window requirement. Additionally, you could check this components to see how this functionality is wired up, so as to understand how to fit them into your scenario:

· The view of the modal window (in the StockTrader application is NewsReaderView.xaml)

· The view model to work with your aforementioned view (NewsReaderViewModel)

· The controller NewsController which interacts between your viewmodels (the parent hosting view model and the popup view model)

You might find useful the StockTrader RI documentation, where you can read more about its main features, how Stock Trader RI works and the technical challenges it addresses, here.

Thanks,

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

 

Dec 17, 2010 at 7:13 PM

Hi Morgan,

As for the lifetime issue you mentioned, you might find the following thread useful:

Also, it would be helpful if you could provide us with a repro sample or more information regarding this and the workaround you've proposed for it.

Thanks,

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

 

Dec 17, 2010 at 10:33 PM

I have only seen it when using the closing X in the right corner. I am guessing before the closing completes and moves on causes a null exception but it can be trapped and recovered.

Dec 20, 2010 at 5:43 PM
Edited Dec 20, 2010 at 5:48 PM

I have got major pieces of it in my application. However I have run into a roadblock. I have a 3rd party chart control and I need to show a popup on the itemclick event of the chart control. I tried to use the stocktrader example where the button click is bound 

<Button Command="{Binding ShowNewsReaderCommand}" ...

I tried something  similar for the chart control however I got an exception.

How could I get the click event handled in the viewmodel?

Thanks.

 

PS: I have also migrated my application to Prism v4 now.

Developer
Dec 20, 2010 at 5:59 PM

Hi Morgan,

You could check the following thread in which there is some insight on the issue of view's garbage collection:

Best way to manage views in a region

I hope you find this helpful. In case you find it is an issue in the Prism Library, you could post it as a work item in the Issue Tracker.

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

Developer
Dec 20, 2010 at 6:00 PM

Hi scorpsteals,

Could you provide us with more information about the exception you're experiencing, so that we can help you troubleshoot your issue?

Thanks.

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

Dec 20, 2010 at 6:35 PM

In XAML: I have

<chart:ChartArea ItemClick="{Binding showPopupCommand}"> 

In the viewModel I have the following lines of code:

 

private readonly ICommand showPopupCommand;

this.showPopupCommand = new DelegateCommand(this.ShowPopupView);



private void ShowPopupView()

{
	//Need to show a popup 
	string test = "test"; //entered this for test to see if I can get to here.

}

 

I am getting an Exception on InitializeComponent()

Failed to assign to property 'Telerik.Windows.Controls.Charting.ChartArea.ItemClick'. 

I am not sure if I am missing any pieces.

Developer
Dec 20, 2010 at 6:48 PM

Hi,

If I understood your exception correctly, it seems to be an error when assigning a command binding to the ItemClick property of the Telerik ChartArea control.

You might find this thread from the Telerik forums useful. As this is not related to Prism, you might find better support in the Telerik forums.

I hope you find this helpful.

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

Dec 26, 2010 at 2:10 AM
mbronzovic wrote:

Hi Morgan,

As for the lifetime issue you mentioned, you might find the following thread useful:

Also, it would be helpful if you could provide us with a repro sample or more information regarding this and the workaround you've proposed for it.

Thanks,

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

 

Found my problem it was related to the regionmanager trying to kill a null view object that was passed to it...  Not a Prism issue but related to the idiot behind the keyboard.