Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReSharper warnings with MVVM

As I implement the MVVM pattern with WPF, I'm finding that ReSharper is often warning me that certain properties are never used in my ViewModels. The problem is that they are being used, but only by the data binding system. Has anyone else encountered this annoyance and is there a way to help ReSharper realize that these properties are, indeed, being used? I am glad, at least, that VS 2010 properly realizes that [Import] tagged members won't "always be null", but hopefully I can fix this issue as well.

like image 282
Dan Bryant Avatar asked May 07 '10 17:05

Dan Bryant


2 Answers

You can use External Annotations to indicate to ReSharper the method is used and thus not to warn you. See the ReSharper docs on that here.

You need to decorate any such methods with [UsedImplicitlyAttribute].

Before using the attribute, you see:

enter image description here

and then, after applying the attribute:

[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] class NotUsed {     public int Field1 { get; set; }     public int Field2 { get; set; } } 
like image 74
wal Avatar answered Sep 19 '22 05:09

wal


Use

<UserControl ... xmlns:vm="clr-namespace:YourProject.ViewModels" mc:Ignorable="d" d:DataContext="{d:DesignInstance vm:SomeClassViewModel}"> 

It 'stick's View to Model. In View you could see model properties and vice versa - in model properties should be used.

like image 30
Adrian Botor Avatar answered Sep 23 '22 05:09

Adrian Botor