【发布时间】:2023-01-09 03:34:54
【问题描述】:
很抱歉或问这个问题,我知道我尝试过的这个社区中有类似的问题并没有解决我的问题。基本上我有一个名为 MainPage.xaml 的视图,其中包含以下代码:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:VideoDemos.Views"
x:Class="VideoDemos.Views.MainPage"
Title="Home Page">
...
<TableView Intent="Settings">
<TableRoot>
<TableSection>
<ImageCell Text="Add new shot"
Detail="Add a new shot, the starting shot is a serve"
ImageSource="Resources/Images/add_icon_3.png"
Command="{Binding AddNewShotComand}"
/>
</TableSection>
</TableView>
...
</ContentPage>
public ICommand AddNewShotComand { set; get; }
public MainPage()
{
InitializeComponent();
MyInit();
AddNewShotComand = new Command(AddNewShotCmd);
}
public void AddNewShotCmd()
{
var a = 5;
}
我有 var a = 5 只是作为调试点,但是,我从来没有达到这一点。
我已经尝试迭代来自微软的这个链接的步骤我很困惑,我已经一步一步地跟随来自微软https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/data-binding/commanding?view=net-maui-7.0的这个链接
我试图将 tableview 意图更改为我们的参数,因为之前的 stackoverlow 似乎表明重叠可能是问题所在,但这并没有解决任何问题或我。
我试图直接从链接复制/粘贴无济于事。
我真的不知道可能是什么问题。
任何帮助都会很棒!
【问题讨论】:
-
你在哪里设置 BindingContext?
-
所以我一直在阅读有关 bindingcontext 或几天的内容,但我不知所措或如何根据我的情况进行设置。