This piece of XAML (in the definition of a ListView
)
<ListView
x:Name="ListViewEpisodes"
Grid.Row="1"
Grid.Column="2"
ItemsSource="{Binding Episodes}">
<ListView.View>
<GridView>
<GridViewColumn Header="Episode Name" Width="Auto" DisplayMemberBinding="{Binding FileName}" />
</GridView>
</ListView.View>
<ListView.ContextMenu>
<ContextMenu DataContext="{Binding RelativeSource={RelativeSource Self}}">
<MenuItem
Header="Delete episode"
Command="w:MainWindow.DeleteEpisode"
<!-- PlacementTarget.SelectedItem not OK according to Resharper -->
CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"/>
</ContextMenu>
</ListView.ContextMenu>
</ListView>
Resharper warning:
Can not resolve property 'SelectedItem' in data context of type 'System.Windows.UIElement'
Now, the XAML does work, when I right click an item, and execute the ContextMenuItem
it does fill the parameter with the content of the Episode
.
Why is Resharper not happy about this?
This is a pretty easy to explain. PlacementTarget
is of type UIElement
that doesn't have Tag
member. ReSharper tries to find member with Tag name but it fails.
At compile time ReSharper is right. ReSharper doesn't know what exactly type would be in run time.
Maybe you need to rewrite your binding expression to:
<ContextMenu DataContext="{Binding Tag, RelativeSource={RelativeSource Self}}" />
It's difficult to say precisely, because it isn't obvious what are you trying to achieve with this binding expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With