【发布时间】:2025-12-19 01:30:06
【问题描述】:
在我的项目中,我使用 C# 创建了一些图像,我想要这些照片的来源,绑定到 My ViewModel 中的属性。
在我的 MVVM 中:
public event PropertyChangedEventHandler PropertyChanged = delegate { };
private string _Light= "dark.png";
public string Light
{
get { return _Light; }
set {
_Light = value;
PropertyChanged(this, new PropertyChangedEventArgs(nameof(Light)));
}
}
在我的 C# 中:
BindingContext = new LightViewModel();
LightViewModel light = new LightViewModel();
Image dark = new Image { Margin = new Thickness(0, -5, 0, 10), HeightRequest = 20, WidthRequest = 20 };
dark.SetBinding(Image.SourceProperty, light.Light);
我将这个 MVVM 与这个 Xaml 一起使用,它是 Property 的工作
<Image Source="{Binding Light}" ></Image>
可以帮助我:)
【问题讨论】:
标签: c# xaml xamarin.forms