C# 值转换器没有';我不能在海关工作
我尝试使用-FlipView控件中的控件。 以下是我所拥有的:C# 值转换器没有';我不能在海关工作,c#,wpf,xaml,user-controls,converter,C#,Wpf,Xaml,User Controls,Converter,我尝试使用-FlipView控件中的控件。 以下是我所拥有的: <flipViewControl:FlipView ItemsSource="{Binding Images}" Name="ImagesFlipView" SelectedIndex="{Binding ElementName=ProductImagesBullets, Path=SelectedIndex, Mode=TwoWay}"
<flipViewControl:FlipView ItemsSource="{Binding Images}" Name="ImagesFlipView"
SelectedIndex="{Binding ElementName=ProductImagesBullets, Path=SelectedIndex, Mode=TwoWay}" Grid.Row="0">
<flipViewControl:FlipView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding FileLocation, Converter={StaticResource ImagePathConverter}}" Stretch="Fill"/>
</DataTemplate>
</flipViewControl:FlipView.ItemTemplate>
</flipViewControl:FlipView>
但是在这个用户控件中,在调试中,我从来没有进入这个转换器(当我在一个简单的单独映像上尝试它时,它是有效的)
这个问题的解决方案是什么?(不会显示图像,因为转换器未为图像应用正确的ImageSource)
我已经创建了一个测试项目与此控制和转换器-它的作品。。。奇怪,非常奇怪
UPD:现在看来
<flipViewControl:FlipView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FileLocation}"></TextBlock>
<!--<Image Source="{Binding FileLocation, Converter={StaticResource ImagePathConverter}}" Stretch="Fill"/>-->
</DataTemplate>
</flipViewControl:FlipView.ItemTemplate>
根本不起作用。我试图设置另一个模板,但它也不起作用。
关于绑定-我添加了转换器只是为了看看绑定是什么样的,绑定是正确的
UPD:当我理解自定义控件应该作为单独的
dll
时,问题就解决了。所以我只需将代码移动到单独的项目中,并添加对主项目的引用 将属性FileLocation更改为
public object FileLocation
{
get
{
try
{
return new BitmapImage(new Uri((string)PathToImage));
}
catch
{
return new BitmapImage();
}
}
}
XAML
不使用转换器?将属性FileLocation更改为
public object FileLocation
{
get
{
try
{
return new BitmapImage(new Uri((string)PathToImage));
}
catch
{
return new BitmapImage();
}
}
}
XAML
不使用转换器?请检查是否在资源块中使用“ImagePathConverter”名称声明转换器。如果您只是使用类名,它将不起作用。@VadimMartynov,是的,我做到了。很好。接下来,确保绑定不会引发错误。您可以检查visual studio中的输出窗口以显示绑定错误。然后,确保您的属性绑定到此绑定。@VadimMartynov,没有错误。。。让我再次检查绑定。注意,
在转换器中返回bi.Clone()
没有意义。相反,只需编写返回bi
。请检查是否在参考资料块中使用“ImagePathConverter”名称声明转换器。如果您只是使用类名,它将不起作用。@VadimMartynov,是的,我做到了。很好。接下来,确保绑定不会引发错误。您可以检查visual studio中的输出窗口以显示绑定错误。然后,确保您的属性绑定到此绑定。@VadimMartynov,没有错误。。。让我再次检查绑定。注意,在转换器中返回bi.Clone()
没有意义。相反,只需编写返回bi
。
<flipViewControl:FlipView ItemsSource="{Binding Images}" Name="ImagesFlipView" SelectedIndex="{Binding ElementName=ProductImagesBullets, Path=SelectedIndex, Mode=TwoWay}" Grid.Row="0">
<flipViewControl:FlipView.ItemTemplate>
<DataTemplate>
<Image Source="{Binding FileLocation}" />
</DataTemplate>
</flipViewControl:FlipView.ItemTemplate>
</flipViewControl:FlipView>