Use DataContext as CommandParameter in WPF
By : user1787768
Date : March 29 2020, 07:55 AM
To fix the issue you can do An empty Binding, without a path, binds directly to the DataContext, so code :
{Binding}
<Button
x:Name="btnMain"
Command="infra:ApplicationCommands.MyCommand"
CommandParameter="{Binding}"
/>
|
How do I set CommandParameter in XAML?
By : user2814557
Date : March 29 2020, 07:55 AM
wish helps you I have the following XAML: , Try using this: code :
<MenuItem x:Name="gridprint"
CommandParameter="{Binding PlacementTarget, RelativeSource=
{RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}" />
|
Cannot set CommandParameter using ElementName
By : Orie Wall
Date : March 29 2020, 07:55 AM
it helps some times The problem is that, like the Popup control, it's a different visual tree. The error is telling you that it is trying to find a property called 'CommandParameter' on a 'RadMenuItem', because this is the DataContext it has within the ContextMenu's visual tree. This will help you: Placement Target
|
how to pass generic list in CommandParameter
By : Simon Sørensen
Date : March 29 2020, 07:55 AM
wish help you to fix your issue If you want to bind collection from (XAML) control for an example from combobox: code :
<ComboBox x:name="combobox" ItemsSource="{Binding Collection}">
<HyperlinkButton Command="{Binding DataContext.HyperlinkGoToCommand}", CommandParameter="{Binding ElementName=combobox, Path=ItemsSource}"></HyperlinkButton>
CommandParameter="{Binding DataContext.YourCollectionPropertyFromViewModel}" or
CommandParameter="{Binding YourCollectionFromViewModel}"
|
Use MenuItem Value as CommandParameter
By : Papaj_G
Date : March 29 2020, 07:55 AM
it helps some times I have the following MenuItem which comes from a Menu (not a ContextMenu): , If you want to send the clicked menuitem context then code :
<MenuItem DisplayMemberPath="Name"
Header="Teams"
ItemsSource="{Binding Teams,
Source={StaticResource Container}}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding OpenTeamPage}"
PassEventArgsToCommand="True"
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
|