WPF和Caliburn Micro切换按钮内的按钮不会触发

时间:2018-08-16 09:46:31

标签: c# wpf xaml caliburn.micro

所以我有一个带文本和内部按钮的切换按钮。问题是我可以单击切换按钮的任何位置并触发,但是如果我尝试单击内部按钮,则切换按钮又会触发...我如何才能确保在单击内部按钮时仅调用内部按钮动作?

这是我的代码:

<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>

1 个答案:

答案 0 :(得分:1)

处理Checked的{​​{1}}和Unchecked事件,而不是处理路由的ToggleButton事件:

Clicked

单击内部按钮时,将触发<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> 。当您在内部按钮外部但在InnerBtnAction内部单击时,将触发ToggleButton