How do I account for bounded properties with Resharper?

My view models have properties that don't interact with any other code, and so Resharper flags them as unused and asks me if I want to delete them. I don't want to turn off the feature; I like seeing code that is not used. Is there an attribute or something to tell resharper that the code is infact being bound to?

Thanks.

6 comments
Comment actions Permalink

Thats what the UsedImplicitly annotations are for!

0
Comment actions Permalink

I've seen that. I really don't like the idea of applying [UsedImplicitly] to every single bound property and view model. I guess if that's what I have to do.

0
Comment actions Permalink

Have you tried setting a d:DataContext / d:DesignInstance on your view?

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:vm="clr-namespace:Your.ViewModel.Namespace"
d:DataContext="{d:DesignInstance Type=vm:YourViewModelType, IsDesignTimeCreatable=True}"

0
Comment actions Permalink

What is necessary to make a view model design time creatable?

0
Comment actions Permalink

It needs a default constructor, and it should avoid any code which might fail at design time. For example, you could check whether the code is running at design time, and replace any database calls with dummy data.

Alternatively, you could just set the IsDesignTimeCreatable property to False (or omit it), and the designer will use an instance of a substitute type with the same properties. You won't see any data at design time, but it should be enough for R# to pick up the bindings.

0
Comment actions Permalink

I just want to say that I tried this and I really like the results. Blend works so much better now. Thanks.

0

Please sign in to leave a comment.