在许多
地方都建议可以使用以下代码在 UWP 中使用圆形图像。
<Ellipse Width="250" Height="250">
<Ellipse.Fill>
<ImageBrush ImageSource="url" />
</Ellipse.Fill>
</Ellipse>
我想要实现的是将图像源绑定到视图模型,例如
<Ellipse Width="250" Height="250">
<Ellipse.Fill>
<ImageBrush ImageSource="{x:Bind ImageUrl}" />
</Ellipse.Fill>
</Ellipse>
但是,每当图像网址为空时,我都会收到异常
{System.ArgumentException: The parameter is incorrect.
value
at Windows.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(Type type, Object value)
at Views.DetailView.DetailView_obj1_Bindings.Update_ImageUrl(String obj, Int32 phase)
at Views.DetailView.DetailView_obj1_Bindings.Update_(Episode obj, Int32 phase)
at Views.DetailView.DetailView_obj1_Bindings.ProcessBindings(ContainerContentChangingEventArgs args)} System.ArgumentException
这是类型不匹配。ImageSource
属性的类型为 ImageSource
,您的ImageUrl
可能是string
。它将使用经典{Binding }
而不是{x:Bind }
,但对于{x:Bind }
,您需要一个将string
转换为ImageSource
的转换器(例如,通过创建新BitmapImage
(。