admin管理员组文章数量:1277896
I have a xaml file with 2 basic buttons: button_1
and Button_2
The problem, is that the first button is responsive, but Button_2
is not.
However, if I move Button_2
above Button_1
in the xaml file, then Button_2
becomes responsive while button_1
is not anymore.
Any idea what I am doing wrong here?
I havent added the VM,as 2 methods are very distinct from each other so I don't think it this matters. SOmething tells me its coming from the xaml file.
I tried to wrap them in <StackLayout>
, just in case the behaviour might change but no.
xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=";
xmlns:x=";
x:Class="App._Views.FolderName.View"
<!-- BUtton 1-->
<StackLayout/>
<Button
Command="{Binding Button1Command}"
CommandParameter="{Binding .}" />
<!-- BUtton 2-->
<Button
Command="{Binding Button2Command}"
CommandParameter="{Binding .}" />
</StackLayout>
</ContentPage>
ViewModel - using breapoint, Button2()
is not accessed.
public partial class VM: ObservableObject, IQueryAttributable
{
[RelayCommand]
private async void Button1()
{
Console.WriteLine("Button1 is accessed");
}
[RelayCommand]
private async void Button2()
{
Debug.WriteLine("Button 2 is clicked")
}
}
I have a xaml file with 2 basic buttons: button_1
and Button_2
The problem, is that the first button is responsive, but Button_2
is not.
However, if I move Button_2
above Button_1
in the xaml file, then Button_2
becomes responsive while button_1
is not anymore.
Any idea what I am doing wrong here?
I havent added the VM,as 2 methods are very distinct from each other so I don't think it this matters. SOmething tells me its coming from the xaml file.
I tried to wrap them in <StackLayout>
, just in case the behaviour might change but no.
xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft/winfx/2009/xaml"
x:Class="App._Views.FolderName.View"
<!-- BUtton 1-->
<StackLayout/>
<Button
Command="{Binding Button1Command}"
CommandParameter="{Binding .}" />
<!-- BUtton 2-->
<Button
Command="{Binding Button2Command}"
CommandParameter="{Binding .}" />
</StackLayout>
</ContentPage>
ViewModel - using breapoint, Button2()
is not accessed.
public partial class VM: ObservableObject, IQueryAttributable
{
[RelayCommand]
private async void Button1()
{
Console.WriteLine("Button1 is accessed");
}
[RelayCommand]
private async void Button2()
{
Debug.WriteLine("Button 2 is clicked")
}
}
Share
Improve this question
edited Feb 24 at 11:46
PhilM
asked Feb 24 at 11:15
PhilMPhilM
4052 silver badges15 bronze badges
4
|
1 Answer
Reset to default 2It will work if you give the method the correct signature so it can generate the RelayCommand.
Avoid async void
and use async Task
instead, or in this case, you don't run async code, so just use a void
method.
[RelayCommand]
private void Button1()
{
Console.WriteLine("Button1 is accessed");
}
alternative:
[RelayCommand]
private async Task Button1Async()
{
Console.WriteLine("Button1 is accessed");
}
本文标签: cMAUIButtons interfere with each otherStack Overflow
版权声明:本文标题:c# - MAUI - Buttons interfere with each other - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741274554a2369651.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<StackLayout/>
and then you later "close" that self-closing element just above the Grid-closing part.) (Why are you nesting StackLayouts and all, and why have two StackLayout elements with a single element each?) – Jon Skeet Commented Feb 24 at 11:20Console
stream and in the other you're logging to theDebug
stream. Where are you expecting to see theConsole
output? – IV. Commented Feb 24 at 16:13