nick_green
nick_green

Reputation: 1664

WPF & Caliburn Micro button inside toggle button does not trigger

So I have a toggle button with text and inner button. The thing is that I can click anywhere in toggle button are and it triggers, but if I try to click inner button, toggle button triggers again... How can I make that when I click on inner button only inner button action is called?

This is my code:

<ToggleButton cal:Message.Attach="TogglePropertyAction" IsChecked="{Binding PropertyEnabled, Mode=OneWay}">
    <StackPanel>
        <TextBlock Text="Sometext" />
        <TextBlock Text="Another inner text">
            <Button
                Content="InnerButton"
                cal:Message.Attach="InnerBtnAction" />
        </TextBlock>
    </StackPanel>
</ToggleButton>

Upvotes: 1

Views: 767

Answers (1)

mm8
mm8

Reputation: 169200

Handle the Checked and Unchecked events for the ToggleButton instead of handling the routed Clicked event:

<ToggleButton cal:Message.Attach="[Event Checked] = [Action TogglePropertyAction];[Event Unchecked] = [Action TogglePropertyAction]"
              IsChecked="{Binding PropertyEnabled, Mode=OneWay}">
    <StackPanel>
        <TextBlock Text="Sometext" />
        <TextBlock Text="Another inner text">
            <Button
                Content="InnerButton"
                cal:Message.Attach="InnerBtnAction" />
        </TextBlock>
    </StackPanel>
</ToggleButton>

When you click in the inner button, InnerBtnAction is triggered. When you click outside the inner button but inside the ToggleButton, TogglePropertyAction is triggered.

Upvotes: 2

Related Questions