Obtain ListBox SelectedItem through ContextMenu with Multibinding in Windows.ResourceHow to loop through all enum values in C#?Styling a ListBoxItem depending on its index in the ListBoxBind SelectedItem in a ListBox to CommandParameter in a ContextMenuBinding to the UserControl which contains the ItemControl dataAdding image to ListBox itemRelativeSource binding not resolvingBinding between two controls declared in the same WPF ContextMenu MenuItemSelected Item of TreeviewWPF create a ListView with ContextMenu inside a WebBrowser using ICommandWPF ContextMenu: MenuItem Icon visibility binding error
Unsolved Problems (Not Independent of ZFC) due to Lack of Computational Power
Default camera device to show screen instead of physical camera
Symlink to directory for easy access: .bashrc, usr/local/bin, something else?
Moons that can't see each other
Why doesn't the Falcon-9 first stage use three legs to land?
Do living authors still get paid royalties for their old work?
Have only girls been born for a long time in this village?
Multicolumn in table not centered
Is there any road between the CA State Route 120 and Sherman Pass Road (Forest Route 22S0) that crosses Yosemite/Serria/Sequoia National Park/Forest?
Syncing bitcoin node with multiple cores
Did Wernher von Braun really have a "Saturn V painted as the V2"?
What happened after the end of the Truman Show?
How could Tony Stark wield the Infinity Nano Gauntlet - at all?
Chess software to analyze games
Can 'in-' mean both 'in' and 'no'?
Land Registry Clause
Sous vide chicken without an internal tempature of 165
Gofer work in exchange for Letter of Recommendation
Use of vor in this sentence
How do you call it when two celestial bodies come as close to each other as they will in their current orbits?
What is the evidence on the danger of feeding whole blueberries and grapes to infants and toddlers?
What can I do to keep a threaded bolt from falling out of it’s slot
Does banks' profitability really suffer under low interest rates
"Silverware", "Tableware", and "Dishes"
Obtain ListBox SelectedItem through ContextMenu with Multibinding in Windows.Resource
How to loop through all enum values in C#?Styling a ListBoxItem depending on its index in the ListBoxBind SelectedItem in a ListBox to CommandParameter in a ContextMenuBinding to the UserControl which contains the ItemControl dataAdding image to ListBox itemRelativeSource binding not resolvingBinding between two controls declared in the same WPF ContextMenu MenuItemSelected Item of TreeviewWPF create a ListView with ContextMenu inside a WebBrowser using ICommandWPF ContextMenu: MenuItem Icon visibility binding error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to use multibinding on a context menu stored in Window.Resources and I can't figure out how to get the SelectedItem of the ListBox I attach the menu to.
I think I need to use PlacementTarget, but can't get anything to work. I tried using FindAncestor, but that didn't work. I also tried getting the listbox by the ElementName to no avail.
<Window ...>
<Window.DataContext>
<local:IPViewModel/>
</Window.DataContext>
<Window.Resources>
<sys:Int32 x:Key="Number">0</sys:Int32>
<sys:Int32 x:Key="NumberLetter">1</sys:Int32>
<sys:Int32 x:Key="NumberLetterNumber">2</sys:Int32>
<local:CombineParams x:Key="CombineParams"/>
<ContextMenu x:Key="DetailMenu">
<MenuItem Header = "Number">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="Binding SwitchLabelMode">
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="StaticResource CombineParams">
<!-- The next line is where I'm not sure what to write to get to the listbox -->
<Binding Source="RelativeSource AncestorType=x:Type ListBox"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
...
</Window.Resources>
...
<ListBox Name="IndexDetailsListBox"
...
ContextMenu="StaticResource DetailMenu"
...>
</ListBox>
...
</Window>
I can't get it to give back anything other than unset value.
I'm grateful for any help. None of the other questions I found have the contextmenu in Window.Resources with MultiBinding which seems to be my issue.
c# .net wpf xaml
add a comment |
I'm trying to use multibinding on a context menu stored in Window.Resources and I can't figure out how to get the SelectedItem of the ListBox I attach the menu to.
I think I need to use PlacementTarget, but can't get anything to work. I tried using FindAncestor, but that didn't work. I also tried getting the listbox by the ElementName to no avail.
<Window ...>
<Window.DataContext>
<local:IPViewModel/>
</Window.DataContext>
<Window.Resources>
<sys:Int32 x:Key="Number">0</sys:Int32>
<sys:Int32 x:Key="NumberLetter">1</sys:Int32>
<sys:Int32 x:Key="NumberLetterNumber">2</sys:Int32>
<local:CombineParams x:Key="CombineParams"/>
<ContextMenu x:Key="DetailMenu">
<MenuItem Header = "Number">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="Binding SwitchLabelMode">
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="StaticResource CombineParams">
<!-- The next line is where I'm not sure what to write to get to the listbox -->
<Binding Source="RelativeSource AncestorType=x:Type ListBox"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
...
</Window.Resources>
...
<ListBox Name="IndexDetailsListBox"
...
ContextMenu="StaticResource DetailMenu"
...>
</ListBox>
...
</Window>
I can't get it to give back anything other than unset value.
I'm grateful for any help. None of the other questions I found have the contextmenu in Window.Resources with MultiBinding which seems to be my issue.
c# .net wpf xaml
add a comment |
I'm trying to use multibinding on a context menu stored in Window.Resources and I can't figure out how to get the SelectedItem of the ListBox I attach the menu to.
I think I need to use PlacementTarget, but can't get anything to work. I tried using FindAncestor, but that didn't work. I also tried getting the listbox by the ElementName to no avail.
<Window ...>
<Window.DataContext>
<local:IPViewModel/>
</Window.DataContext>
<Window.Resources>
<sys:Int32 x:Key="Number">0</sys:Int32>
<sys:Int32 x:Key="NumberLetter">1</sys:Int32>
<sys:Int32 x:Key="NumberLetterNumber">2</sys:Int32>
<local:CombineParams x:Key="CombineParams"/>
<ContextMenu x:Key="DetailMenu">
<MenuItem Header = "Number">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="Binding SwitchLabelMode">
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="StaticResource CombineParams">
<!-- The next line is where I'm not sure what to write to get to the listbox -->
<Binding Source="RelativeSource AncestorType=x:Type ListBox"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
...
</Window.Resources>
...
<ListBox Name="IndexDetailsListBox"
...
ContextMenu="StaticResource DetailMenu"
...>
</ListBox>
...
</Window>
I can't get it to give back anything other than unset value.
I'm grateful for any help. None of the other questions I found have the contextmenu in Window.Resources with MultiBinding which seems to be my issue.
c# .net wpf xaml
I'm trying to use multibinding on a context menu stored in Window.Resources and I can't figure out how to get the SelectedItem of the ListBox I attach the menu to.
I think I need to use PlacementTarget, but can't get anything to work. I tried using FindAncestor, but that didn't work. I also tried getting the listbox by the ElementName to no avail.
<Window ...>
<Window.DataContext>
<local:IPViewModel/>
</Window.DataContext>
<Window.Resources>
<sys:Int32 x:Key="Number">0</sys:Int32>
<sys:Int32 x:Key="NumberLetter">1</sys:Int32>
<sys:Int32 x:Key="NumberLetterNumber">2</sys:Int32>
<local:CombineParams x:Key="CombineParams"/>
<ContextMenu x:Key="DetailMenu">
<MenuItem Header = "Number">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="Binding SwitchLabelMode">
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="StaticResource CombineParams">
<!-- The next line is where I'm not sure what to write to get to the listbox -->
<Binding Source="RelativeSource AncestorType=x:Type ListBox"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
</MenuItem>
...
</Window.Resources>
...
<ListBox Name="IndexDetailsListBox"
...
ContextMenu="StaticResource DetailMenu"
...>
</ListBox>
...
</Window>
I can't get it to give back anything other than unset value.
I'm grateful for any help. None of the other questions I found have the contextmenu in Window.Resources with MultiBinding which seems to be my issue.
c# .net wpf xaml
c# .net wpf xaml
asked Mar 27 at 14:11
user10891785user10891785
133 bronze badges
133 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your problem is, that you assign RelativeSource- object to the Source property of the Binding object. RelativeSource- object belongs to the RelativeSource-property.
So you get your List to the multi value converter:
<MultiBinding Converter="StaticResource CombineParams">
<Binding Path="PlacementTarget" RelativeSource="RelativeSource AncestorType=x:Type ContextMenu"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
1
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
1
You are welcome! :)
– Rekshino
Mar 27 at 14:53
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379343%2fobtain-listbox-selecteditem-through-contextmenu-with-multibinding-in-windows-res%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your problem is, that you assign RelativeSource- object to the Source property of the Binding object. RelativeSource- object belongs to the RelativeSource-property.
So you get your List to the multi value converter:
<MultiBinding Converter="StaticResource CombineParams">
<Binding Path="PlacementTarget" RelativeSource="RelativeSource AncestorType=x:Type ContextMenu"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
1
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
1
You are welcome! :)
– Rekshino
Mar 27 at 14:53
add a comment |
Your problem is, that you assign RelativeSource- object to the Source property of the Binding object. RelativeSource- object belongs to the RelativeSource-property.
So you get your List to the multi value converter:
<MultiBinding Converter="StaticResource CombineParams">
<Binding Path="PlacementTarget" RelativeSource="RelativeSource AncestorType=x:Type ContextMenu"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
1
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
1
You are welcome! :)
– Rekshino
Mar 27 at 14:53
add a comment |
Your problem is, that you assign RelativeSource- object to the Source property of the Binding object. RelativeSource- object belongs to the RelativeSource-property.
So you get your List to the multi value converter:
<MultiBinding Converter="StaticResource CombineParams">
<Binding Path="PlacementTarget" RelativeSource="RelativeSource AncestorType=x:Type ContextMenu"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
Your problem is, that you assign RelativeSource- object to the Source property of the Binding object. RelativeSource- object belongs to the RelativeSource-property.
So you get your List to the multi value converter:
<MultiBinding Converter="StaticResource CombineParams">
<Binding Path="PlacementTarget" RelativeSource="RelativeSource AncestorType=x:Type ContextMenu"/>
<Binding Source="StaticResource Number"/>
</MultiBinding>
answered Mar 27 at 14:43
RekshinoRekshino
3,3642 gold badges10 silver badges36 bronze badges
3,3642 gold badges10 silver badges36 bronze badges
1
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
1
You are welcome! :)
– Rekshino
Mar 27 at 14:53
add a comment |
1
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
1
You are welcome! :)
– Rekshino
Mar 27 at 14:53
1
1
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
That works perfectly. Thank you so much. I'd upvote you but it won't let me under 15 reputation.
– user10891785
Mar 27 at 14:51
1
1
You are welcome! :)
– Rekshino
Mar 27 at 14:53
You are welcome! :)
– Rekshino
Mar 27 at 14:53
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55379343%2fobtain-listbox-selecteditem-through-contextmenu-with-multibinding-in-windows-res%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown