问题描述
我想设置FallbackValue的情况下,当我转换器不能打电话,但我不知道该怎么做。
<图像来源={结合FallbackValue =图片/ Unknown.png,路径= LatestPosition.DeviceFamily,转换器= {X:静态CONV:ConverterSet.DeviceTypeToImageSourceconverter}} NAME =此搜索拉伸=填充保证金=5,8WIDTH =150HEIGHT =150Grid.RowSpan =4/>
在转换器外部图像
路径看起来像当LatestPosition!= NULL图像被以适当的方式设置。
私有静态只读的ImageSource装置1 =新的BitmapImage(新的URI(/图片/ dev1.png,UriKind.Relative));
私人静态只读的ImageSource DEV2 =新的BitmapImage(新的URI(/图片/ dev2.png,UriKind.Relative));
有关Image控件,当你与一个URI字符串绑定的源属性,它会自动转换URI为BitmapImage的。
但是,如果你设置FallbackValue和TargetNullValue为URI字符串,
它不会显示。
您需要将其设置为BitmapImage的:
< Window.Resources>
<的BitmapImage X:键=DefaultImageUriSource =/资源;组件/图片/ Default.jpg/>
< /Window.Resources><图像宽度=128
高度=128
的HorizontalAlignment =左
VerticalAlignment =顶部
来源={结合照片,FallbackValue = {StaticResource的DefaultImage},
TargetNullValue = {StaticResource的DefaultImage}}/>
由于我们设置了FallbackValue和TargetNullValue作为BitmapImage的的静态资源,
它的工作原理。
I'm trying to set FallbackValue in case when my converter cannot be call, but I'm not sure how to do that.
<Image Source="{Binding FallbackValue="Pictures/Unknown.png", Path=LatestPosition.DeviceFamily, Converter={x:Static conv:ConverterSet.DeviceTypeToImageSourceconverter}}" Name="image1" Stretch="Fill" Margin="5,8" Width="150" Height="150" Grid.RowSpan="4" />
Paths of external images in converter looks like that and when LatestPosition!=null the image is set in proper way.
private static readonly ImageSource Dev1 = new BitmapImage(new Uri("/Pictures/dev1.png", UriKind.Relative));
private static readonly ImageSource Dev2 = new BitmapImage(new Uri("/Pictures/dev2.png", UriKind.Relative));
For the Image control, when you Binding the Source property with a URI string, it will automatically convert the URI to a BitmapImage.But if you set the FallbackValue and TargetNullValue as URI string,it will not display.
You need to set it as BitmapImage:
<Window.Resources>
<BitmapImage x:Key="DefaultImage" UriSource="/Resources;component/Images/Default.jpg" />
</Window.Resources>
<Image Width="128"
Height="128"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Source="{Binding Photo,FallbackValue={StaticResource DefaultImage},
TargetNullValue={StaticResource DefaultImage}}" />
As we set the FallbackValue and the TargetNullValue as StaticResource of BitmapImage,It works.
这篇关于如何设置FallbackValue作为路径外部图像文件的约束力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!