AG_E_PARSER_BAD_PROPERTY_VALUE [线路:50位置:45]

时间:2011-04-30 17:12:51

标签: silverlight windows-phone-7

这是我的ApplicationBar代码(由于数据绑定导致错误的代码)

 <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" >
            <shell:ApplicationBarIconButton IconUri="/icons/prevItem.png" x:Name="prevItem"
                                            IsEnabled="{Binding Path=IsPrevTopicButtonEnabled}"
                                            Text="Prev item" Click="prevItem_Click">

            </shell:ApplicationBarIconButton>
            <shell:ApplicationBarIconButton IconUri="/icons/nextItem.png" 
                                            IsEnabled="{Binding Path=IsNextTopicButtonEnabled}"
                                            Text="Next item" x:Name="nextItem" Click="nextItem_Click"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="mnuPrevItem" Text="{Binding Path=PreviousTopic.Title}"/>
                <shell:ApplicationBarMenuItem x:Name="mnuNextItem" Text="{Binding Path=NextTopic.Title}"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

这些是我在代码隐藏中的属性: -

public static readonly DependencyProperty PreviousTopicProperty = DependencyProperty.Register("PreviousTopic",
    typeof(Topic), typeof(ArticleViewer), new PropertyMetadata(null));
public Topic PreviousTopic
{
    get { return GetValue(PreviousTopicProperty) as Topic; }
    set
    {

        SetValue(PreviousTopicProperty, value);
    }
}

public static readonly DependencyProperty NextTopicProperty = DependencyProperty.Register("NextTopic",
    typeof(Topic), typeof(ArticleViewer), new PropertyMetadata(null));
public Topic NextTopic
{
    get { return GetValue(NextTopicProperty) as Topic; }
    set
    {

        SetValue(NextTopicProperty, value);
    }
}

public static readonly DependencyProperty IsNextTopicButtonEnabledProperty = DependencyProperty.Register("IsNextTopicButtonEnabled",
    typeof(bool), typeof(ArticleViewer), new PropertyMetadata(true));
public bool IsNextTopicButtonEnabled
{
    get { return (bool)GetValue(IsNextTopicButtonEnabledProperty); }
    set
    {

        SetValue(IsNextTopicButtonEnabledProperty, value);
    }
}

public static readonly DependencyProperty IsPrevTopicButtonEnabledProperty = DependencyProperty.Register("IsPrevTopicButtonEnabled",
typeof(bool), typeof(ArticleViewer), new PropertyMetadata(true));
public bool IsPrevTopicButtonEnabled
{
    get { return (bool)GetValue(IsPrevTopicButtonEnabledProperty); }
    set
    {

        SetValue(IsPrevTopicButtonEnabledProperty, value);
    }
}

在construtor中我有这一行: -

this.DataContext = this;

绑定工作不正常,但我不明白为什么!我知道INotifyPropertyChanged不能很好地与WP7一起使用Silverlight 4.0。但我已经有了DependencyProperties。我还能做些什么呢?

提前致谢:)

1 个答案:

答案 0 :(得分:2)

ApplicationBar作为一个控件有点奇怪......请参阅这篇文章"Why application bar is not a FrameworkElement?"

我认为因为ApplicationBar不是FrameworkElement,所以你不能在其中绑定数据 - 类似于Derek对Getting AG_E_PARSER_BAD_PROPERTY_VALUE while data binding in WP7 User control的回答

我很遗憾地说你可能只需要在CodeBehind中调整ApplicationBar而不是通过数据绑定 - 请参阅Change applicationbar buttonicon at runtime