admin管理员组文章数量:1123188
I have a custom control as follows:
public partial class MyControl : ContentView
{
public event EventHandler? MyClicked;
public MyControl()
{
InitializeComponent();
InternalCommand = new Command(
execute: () =>
{
MyClicked?.Invoke(this, EventArgs.Empty);// breakpoint is added here.
},
canExecute: () => true
);
}
public ICommand InternalCommand { get; set; }
}
<ContentView
...
x:Name="This">
<Button
Command="{Binding InternalCommand,Source={Reference This}}"
Text="Click Me" />
</ContentView>
A page can subscribe to the control's clicked event as follows:
public partial class MyPage : ContentPage
{
public MyPage()
{
InitializeComponent();
}
private void MyControl_MyClicked(object sender, EventArgs e)
{
DisplayAlert("MyControl_MyClicked", "Clicked", "Ok");
}
}
<ContentPage
...
xmlns:loc="clr-namespace:MyProject"
>
<loc:MyControl
MyClicked="MyControl_MyClicked" />
</ContentPage>
In debug mode the breakpoint never gets reached when I click the button. What is the culprit?
本文标签: mauiWhat causes the ICommand of the ContentView to never be invokedStack Overflow
版权声明:本文标题:maui - What causes the ICommand of the ContentView to never be invoked? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736556271a1944581.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论