简体   繁体   English

值转换器未称为XAML

[英]Value Converter not Being Called XAML

I have put breakpoints inside the Value Converter and they are never triggered, but the page renders with no image being shown. 我将断点放置在Value Converter中,但从未触发过断点,但是页面呈现时未显示任何图像。

The 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}"/>

The CS: 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();
    }
}

From what I can understand (by process of trial and elimination and looking at what exceptions are thrown) the problem is coming with part of the XAML where I am trying to bind to the value. 据我所知(通过尝试和消除的过程,并查看抛出了哪些异常),问题出在我试图绑定到值的XAML的一部分上。

At a breakpoint the value at App.Main.Game.CurrentLevel.CurrentPart.Image is being set correctly (ie is an instance of WinPhone8ImageProvider ). 在断点处, App.Main.Game.CurrentLevel.CurrentPart.Image的值已正确设置(即,是WinPhone8ImageProvider的实例)。

It turns out this was nothing to do with the converter at all. 事实证明,这与转换器完全无关。 The value was binding before the image had loaded (so the source was empty). 该值在映像加载之前已绑定(因此源为空)。 For future reference check to make sure you are implementing the INotifyPropertyChanged correctly in your view models. 供将来参考,以确保您在视图模型中正确实现了INotifyPropertyChanged

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM