[英]Value Converter not Being Called XAML
我将断点放置在Value Converter中,但从未触发过断点,但是页面呈现时未显示任何图像。
XAML:
xmlns:datatypes="clr-namespace:DataTypes_Portable;assembly=DataTypes_WinPhone8"
...
<phone:PhoneApplicationPage.Resources>
<datatypes:WinPhone8ImageConverter x:Key="ImageConverter" />
</phone:PhoneApplicationPage.Resources>
...
<Image x:Name="LevelImage" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Width="Auto" Margin="0" Grid.ColumnSpan="5" Source="{Binding Converter={StaticResource ImageConverter}, Path=App.Main.Game.CurrentLevel.CurrentPart.Image}"/>
CS:
public class WinPhone8ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var imageProvider = value as WinPhone8ImageProvider;
return imageProvider.Image;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
据我所知(通过尝试和消除的过程,并查看抛出了哪些异常),问题出在我试图绑定到值的XAML的一部分上。
在断点处, App.Main.Game.CurrentLevel.CurrentPart.Image
的值已正确设置(即,是WinPhone8ImageProvider
的实例)。
事实证明,这与转换器完全无关。 该值在映像加载之前已绑定(因此源为空)。 供将来参考,以确保您在视图模型中正确实现了INotifyPropertyChanged
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.