Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding/Wiring events to button in an ItemsControl nested inside an ItemsControls DataTemplate
    primarykey
    data
    text
    <p>My question is very similiar to this: (<a href="https://stackoverflow.com/questions/6891116/binding-events-to-buttons-in-an-itemscontrol">Binding events to buttons in an ItemsControl</a>) but I didn't found a solution there. I have an ItemsControl and inside its DataTemplate, I have another ItemsControl. The items in the outer control contain classes that have some properties, and one of the properties is a collection. The inner ItemsControl source is binded to this collection, and inside the inner controls DataTemplate there is a Button.</p> <p>My problem is that when I wire up an event for the button (.. Click="dummyfunc") and try to run the project, I get an unhandled XamlParseException (4004) and says that "Failed to assign to property 'System.Windows.Controls.Primitives.ButtonBase.Click'" I declared my event handler in the CodeBehind of the page in which the outer ItemsControl is placed in the Xaml. And it works fine for the buttons placed in the outer controls DataTemplate. But in the inner controls template, I just cant wire up any events.</p> <p>One thing works:</p> <pre><code>&lt;HyperlinkButton Content="x"&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="Click"&gt; &lt;ei:CallMethodAction MethodName="DeleteMe" TargetObject="{Binding}"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;/HyperlinkButton&gt; </code></pre> <p>But this triggers only a method (DeleteMe) which is implemented in the item I mentioned above, that has some properties and a collection.</p> <p>But instead of this, I need to handle the events in the inner control with a usual method:</p> <pre><code>public void dummyfunc(object sender, RoutedEventArgs e){...} </code></pre> <p>(so i can get the button that fired the event for example: </p> <pre><code>sender as HyperinkButton </code></pre> <p>or </p> <pre><code>e.OriginalSource as HyperlinkButton </code></pre> <p>I suppose the problem is that the event is not bubbled up and I get the parse exception because the parser cannot find the event handler declaration in the actual scope, which apparently is not the CodeBehind for the inner control :(</p> <p>The reason I need this, is because I would like to do some custom UI logic in code, and trigger the DeleteMe logic somehow only after this.</p> <p>Thanks, Bálint</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload