2013-04-05 39 views
0

我已经把价值转换器内的断点,他们从来没有触发,但页面呈现没有图像显示。价值转换器不被称为XAML

的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的实例)。

回答

1

事实证明,这与转换器根本没有关系。在图像加载之前,该值是绑定的(所以源代码是空的)。为了将来的参考检查,以确保您在视图模型中正确实施INotifyPropertyChanged