Suggesting public properties used in WPF binding can be made private in error.

ReSharper is suggesting my ViewModel public properties I use in binding can be made private in error.

This happens with properties used by Views that do not have a known DataContext at design time.

If I follow the advice from ReSharper and make my properties private the binding fails at runtime.

How can i let resharper know that the particular property is being used in Binding and it cannot be made private ?

0
1 comment

If you can set a design-time data context, that should resolve it:

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}"

Otherwise, you'll probably need to decorate your properties with the [UsedImplicitly] attribute; or decorate the view-model with [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)].

https://www.jetbrains.com/help/resharper/Reference__Code_Annotation_Attributes.html

0

Please sign in to leave a comment.