【发布时间】:2021-05-13 14:39:20
【问题描述】:
我真的不明白我做错了什么,我使用了工具包扩展器,并且我试图在点击扩展器标题时调用一个方法。根据他们的文档:
ICommand 类型的命令,在点击 Expander 标头时执行。
所以我尝试了这个:
<xct:Expander Command="{Binding GetMathSubCatgories}">
<xct:Expander.Header>
<Frame Padding="10" Margin="10" HasShadow="False" BorderColor="LightGray" VerticalOptions="CenterAndExpand">
<StackLayout Orientation="Horizontal">
<Image Source="{Binding icon}" WidthRequest="25" HeightRequest="25"></Image>
<Label Text="{Binding name}" TextColor="{Binding textColor}" FontSize="Large" FontAttributes="Bold" HeightRequest="35" VerticalOptions="CenterAndExpand"></Label>
</StackLayout>
</Frame>
</xct:Expander.Header>
<Grid Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListView x:Name="SubCategories" ItemsSource="{Binding subCategories}" ItemSelected="SubCategories_ItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout>
<Label Text="{Binding name}" TextColor="#02cc9d" FontAttributes="Bold" HeightRequest="35" VerticalOptions="CenterAndExpand"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</xct:Expander>
在我的代码后面:
public Command GetMathSubCatgories
{
get
{
return new Command((obj) =>
{
Console.Write("Here");
});
}
}
但它没有被调用,我做错了什么?
这是我的完整代码:
public partial class AssignTaskPage : ContentPage
{
public AssignTaskPage()
{
InitializeComponent();
GetMathSubCatgories = new Command(() => MathSubCatgoriesCommand());
}
public ICommand GetMathSubCatgories { get; private set; }
void MathSubCatgoriesCommand()
{
Console.Write("Here");
}
}
【问题讨论】:
-
在“新命令”中删除
obj怎么样 -
还是不行
-
你是设置断点,还是看输出。像这样
Debug.WriteLine("Here");在 Xamarin 中正常检查输出 -
GetMathSubCatgories是在您的代码隐藏中还是在您的 VM 中定义的?命令通常位于 VM 中。
标签: c# xamarin.forms