![](/img/trans.png)
[英]How to bind the BackgroundColor property of a view to a View Model in Xamarin Forms?
[英]MVVM Xamarin Forms - Command Pararameter to Bind View Model property
我有以下圖像,其中帶有從視圖模型調用命令的點擊手勢識別器:
<Image IsVisible="False" Aspect="Fill" Grid.Column="1" HorizontalOptions="Start" VerticalOptions="Center" Source="po.png" x:Name="img2">
<Image.GestureRecognizers>
<TapGestureRecognizer x:Name="gRcgImg2" Command="{Binding FalaCommand}" CommandParameter="po" />
</Image.GestureRecognizers>
</Image>
當單擊另一個圖像時,我需要更改該命令參數,並且我需要通過視圖模型來完成這一切,你能提供我這樣做的方法嗎?
最好的方法是綁定一些具有此信息的值。 例如,您可以傳遞 Image.Source 並在代碼中添加正確的行為。 例如:
CommandParameter="{Binding Image.Source RelativeSource={RelativeSource AncestorType=Image}}"
有了這個,您可以過濾和檢測發送點擊命令的圖像。
[編輯] 此處,如何從命令更改Image.Source
:
public ICommand MyCommand => new Command((ImageSource) obj) =>
{
obj = ImageSource.FromFile(filename);
});
也許你需要刷新圖像,我不確定。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.