Resharper and WPF MVVM

Hi,

I've got problem with finding code issues in  WPF project. Currently I'm using Resharper 2016.2.2

It's suggesting that public Properties in ViewModel should be private, but they can't be private (according to MVVM mechanism to work properly). Is there any solution for this problem?

I've read that I can use Agent Mulder pluggin, but my team doesn't want to use Agent Mulder plugin because it's not supported anymore.

 

0
5 comments

Have you tried adding a design-time datacontext to your view?

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
d:DataContext="{d:DesignInstance vm:YourViewModel}"
1
Avatar
Permanently deleted user

Many thanks for your fast answer.  I didn't know anything about design-time datacontext. Now I have tested it and found it very usefull. But it still doesn't solve my main problem.

When I'm setting DataContext in View problem doesn't exist. The problem is when I'm setting view's DataContext in code behind. I can't set DataContext in View because my ViewModel class doesn't have parametless constructor. 

1

There are some suggestions for workarounds on this StackOverflow thread.

You don't need to set the DataContext in the XAML; you just need to set the design-time DataContext (d:DataContext), so that R# knows that the view and viewmodel are linked. Any properties you use in the view should then not be marked as "unused", and the view should be included in the "usages of" navigation.

1
Avatar
Permanently deleted user

Many thanks Richard for your help. I've installed newest version of Resharper, rebuilded project and it works:-)

0
Avatar
Permanently deleted user

It works only  when I'm using  design-time datacontext you have send.

0

Please sign in to leave a comment.