簡體   English   中英

值轉換器未稱為XAML

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM