【发布时间】:2018-08-16 14:14:52
【问题描述】:
我正在使用 ReactiveUI 将按钮绑定到 ReactiveCommand 但它没有响应它,所以我在这里错过了什么??
这是 LikeCommand
LikesCommand = ReactiveCommand.Create<Button>(LikeChanges);
private void LikeChanges(Button sender)
{
sender.Clicked += (s, e) =>
{
_newsFeed.LikesNum++;
_newsFeed.BackgroundColor = Color.White;
_newsFeed.TextColor = Color.DodgerBlue;
RaisePropertyChanged();
};
}
这是删除命令
DeleteCommand = ReactiveCommand.Create<NewsFeed>(DeleteItem);
public async void DeleteItem(NewsFeed news)
{
var res = await CoreMethods.DisplayAlert("OH !", "Are you sure?",
"Yes", "No");
if (res)
{
NewsFeeds.Remove(news);
RaisePropertyChanged();
}
}
这是我在列表视图中 viewCell 中的按钮
<Button Text="{Binding LikesNum , StringFormat='Like {0}'}"
x:Name="btnLike"
Command="{Binding LikesCommand}"
BackgroundColor="{Binding BackgroundColor}"
TextColor="{Binding TextColor}"
HorizontalOptions="StartAndExpand" />
<Button Text="Delete"
x:Name="btnLike"
Clicked="Button_OnClicked"
Command="{Binding DeleteCommand}"
HorizontalOptions="End" />
【问题讨论】:
-
首先,删除 LikeChanges 中的 sender.Clicked 委托。 ReactiveCommand 负责处理 clicked 事件。您只需要该 lambda 中的内容。让你的 ReactiveCommand 签名看起来像 ReactiveCommand
LikesCommand
标签: xaml xamarin.forms reactiveui