Quantcast
Channel: patterns & practices: Prism
Viewing all 1878 articles
Browse latest View live

Reviewed: Prism 5.0 for .NET 4.5 (七月 25, 2014)

$
0
0
Rated 5 Stars (out of 5) - a very wonderful tool for us to use mvvm

New Post: PRISM 5 potential BindableBase Class Update

$
0
0
Hello,

I really like the bindablebase class in PRISM 5, however it looked like it was lacking a little bit in its 'SetProperty' method. I personally am not a huge fan of using the static string name for the OnPropertyChanged method call as I find it to be bit error prone and hard to debug, so I tend to use the expression implementation of OnPropertyChanged. As such, I assumed there would be a 'SetProperty' method that would work in much the same way
but much to my chagrin, there is not anyway to call the 'SetProperty' method using an expression.

So here is another implementation of the SetProperty method that has an optional expression instead of string that calls the notify property changed event. Here's the code I used in my code base to accomplish it, maybe it will help others:
protected bool SetProperty<T>(ref T storage, T value, Expression<Func<T>> propertyExpression)
   {
       if (base.SetProperty<T>(ref storage, value))
       {
           var _propertyName = Microsoft.Practices.Prism.Mvvm.PropertySupport.ExtractPropertyName(propertyExpression);
           this.OnPropertyChanged(_propertyName);
           return true;
       }
       else return false;
   }


New Post: How to retrieve/import object using MEF in Prism?

$
0
0
I have a requirement to have one object (RuleFile), representing file to be serialized, across the whole application like word (*.docs) file that will be associated with my application.

I am using Prism 5 along with MEF as a dependency injection container.
[Export]
[Serializable()]
public class RuleFile : NotificationBase, IRuleFile { }
Now i have decorated the object with [Export] and trying to import it using [Import] in one of the MyViewModel but it is giving null.
public class MyViewModel : ViewModelBase
{
    [Import]
    private RuleFile RuleFile; // 'null' coming here
}
Kindly direct me what am i missing? Or tell me any other way to best handle this scenario.

Created Unassigned: Prism 5 WPF XAML designer error "Your views must implement IView" [10685]

$
0
0
When using ViewModelLocator.AutoWireViewModel I am getting "Your views must implement IView" design time error even though the views implement IView

I am using VS2013 Update 2

New Post: Convert wpf application to DLL

$
0
0
I realize this thread is old but I'm trying to do the same thing. I have a WPF/Prism EXE that I converted to a DLL that I need to start from a Class Library. I created an entry point that calls the bootstrapper and the shell window appears but fails when I try to inject a view into a region as the RegionManager doesn't recognize the region names. (The EXE I started with works as expected so it's setup as a valid Prism application). I did verify that ConfigureAggregateCatalog is being called and my MEF exports are being picked up so it's not an issue there.

I tried the same thing with the Hello World Quickstart and the shell opens but the module isn't loaded into the region.

Here is my code from InitializeShell in the bootstrapper:
        base.InitializeShell();

        Window mainWindow = (Window)CreateShell();
        mainWindow.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
            {
                mainWindow.Show();
            }
        ));
        System.Windows.Threading.Dispatcher.Run();   
Any ideas?

Thanks,
-Scott

New Post: DataContext in XAML gives: Object reference not set to an instance of an object

$
0
0
Hi,
I'm using XAML: ...
<Window .....       xmlns:view="clr-namespace:SampleApp.ViewModel"
        mc:Ignorable="d"
        Title="Sample" Height="500" Width="700">
    <Window.DataContext>
        <view:Datamodel/> <!-- This gives the error Object reference not set to an instance of an object -->
    </Window.DataContext>
The line with <view:Datamodel/> gets red error indicators, but at runtime everything is ok.
Assumption: This is not really an error
Question: Is there a fix/workaround and still continue with the declarative assignment of the viewmodel?

Best regards
Bo

New Post: Incompatibilities between Prism 5 and NET 4.5.2

$
0
0
Hi Markus,

I have the same problem. Did you find a solution for it already?

Regards,
Patrick

New Post: DataContext in XAML gives: Object reference not set to an instance of an object

$
0
0
Good Day,

In your ViewModel, are you using GetIsInDesignMode code which is throwing some exceptions ?

Something like :
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
  // Some Object reference not set which would be throwing an uncatch exception here.
}
Regards

Dimitri

New Post: DataContext in XAML gives: Object reference not set to an instance of an object

$
0
0
Dimitri,
nothing like that. Just creating some properties like ObservableCollections, Commands and some more data classes are created in CTOR.
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
{
  // Some Object reference not set which would be throwing an uncatch exception here.
}
Regards

Bo

New Post: DataContext in XAML gives: Object reference not set to an instance of an object

$
0
0
HI Bo,

I had a similar issue and after commenting out just about everything in my CTOR I was able to find my issue while de-commenting one functionality at a time.

Regards,

Dimitri

New Post: DataContext in XAML gives: Object reference not set to an instance of an object

$
0
0
Finally got it:
  • 1st try: Using devenv to debug devenv did not show up with any exception loading the view into the designer. Output window gave no indication of error but the red marks continued.
  • 2nd try: removed everything from CTOR an rebuild it line by line until I hit the mark!
Application.Current.MainWindow.Closing += (o, e) => { };
One should always use
Application.Current.Exit += (o, e) => { };
Solved it,
Thanks for contributing

Bo

Reviewed: Prism 5.0 for .NET 4.5 (八月 03, 2014)

$
0
0
Rated 4 Stars (out of 5) - A good framework

New Post: Incompatibilities between Prism 5 and NET 4.5.2

$
0
0
Hi Patrick,

I downloaded the PRISM source to check out the reason and found out that while most of the projects are Built for .NET 4.5.1 and can simply be switched, a few of them have been configured for multiple target platforms.
I can only assume that those are portable class libraries since I've never worked with those before
Although you can choose the version of the .NET-Framework, you can only choose a version up to 4.5.1.
Again I assume this is because 4.5.2 is not available for PCL's yet (anyone correct me if I'm wrong).

Anyway there are two ways to fix this, both not really satisfying.
  1. Of course you can simply switch over to .NET Framework 4.5.1 - it's what we did with gritting teeth. Thus you will still use the NuGet provided packages and benefit from the updating mechanism it provides.
  2. You can download the source and set the Projects to compile for 4.5.2.
I've tried the second approach too, since it didn't take much time. It does take some meddling with the .csproj-Files of the projects which are set to have multiple Targets in order to be able to select 4.5.2 as single target. Also you need to add some references to them, but you will see them alright if you try to compile.
Mainly you'll want to remove the content of the TargetFrameworkProfile-Tag and the whole ProjectTypeGuids-Tag. Plus in order to get it to compile you want to change the import at the end from <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> to <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

But on the other hand that means you either can't update PRISM or you need to apply these patches for each update (which you get by updating the sources manually) and recompile yourself until 4.5.2 is supported out of the box.

Regards,
Markus

New Post: Incompatibilities between Prism 5 and NET 4.5.2

$
0
0
HI Markus,

Thanks for the answer.

Still I find it strange that we get this error because 4.5.2 should be backwards compatible with 4.5.1.
So I like to know from the dev team why it's complaining about it.

The errors I'm getting are a little different. But I'm using the DelegateCommand<T>

first error is - The type 'System.Windows.Input.ICommand' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
second error is - The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

We don't use Nuget to update the files so I can recompile the sources. That's an options for us.

Regards,
Patrick

New Post: Incompatibilities between Prism 5 and NET 4.5.2


New Post: Reset view model in Prism 5.0 when clicking new button

$
0
0
Hello

How can I reset my viewmodel when the user clicks new button?

For example:

If I have a view NewCustomer and upon save, the data is saved to the DB and the newly created account number is displayed. But when the user clicks the New button in the screen, I want the view to be reinitialized. Or for that matter if the user clicked Cancel in the screen to clear all changes.

How can I achieve this? I am using Unity as my container.

Here is my quick intro of view and viewmodels that I am using:

Top Region - Menu
Main Region - Main content
Bottom Region - Status Bar control

The main content is shown using the following view and viewmodels

Home - HomeViewModel
NewCustomer - NewCustomerViewModel
CustomerSearch - CustomerSearchViewModel

I use IRegionMemberLifetime in NewCustomer and set to false upon save. So when the user navigates away and returns, I can reset the viewmodel. I will implement INavigationAware to prompt to save changes if needed.

But I can't figure out how I can reset the viewmodel when I click the New button in the NewCustomer view itself.

I have my IRegionManager only in the Module initializer class. I use regionmanger.requestnavigate to navigate in the main region between views.

Thanks for your help and input. Note: I am using Prism 5.0

New Post: RequestNavigate method does not find the view

$
0
0
In my understanding, I think you will initialize the views using the Container.
You can't use CustomView view = new CustomView() yourself.

Please use container.RegisterType<object, CustomView>("CustomView"); in your module initializer.

or CustomView view = container.Resolve<CustomView>();

Hope this helps.

Commented Unassigned: Support Universal App for Prism [10642]

$
0
0
Prism does not work for Universal Windows Phone 8.1 and Windows 8.1 Apps, can that please be supported?
Comments: ** Comment from web user: dsoltesz **

Any further update on this? Project templates?

New Post: PRISM 4 MVVM data paging

$
0
0
Hi lucianotcorreia & Kiran
Is this only work with Silverlight ? I tried this in WPF. When I set the reference to 'System.Windows.Data.dll' in Silverlight SDK folder (for IPagedCollectionView) It gives following compilation error.
Unknown build error, 'Cannot resolve dependency to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.

I'm using Visual Studio 2010 Ultimate. If it is not possible with WPF is there any other solution for loading data dynamically in WPF ?

Thanks

New Post: how to create multi-shell window application using Prism 4.0 and MEF with MVVM

$
0
0
I am also interested to have multiple shell view. Appreciate if you guys share the sample code for it or give me direction to accomplish it. Thanks.
Viewing all 1878 articles
Browse latest View live