2011-04-30 41 views
0

這是我的應用程序任務的代碼(該代碼,這是造成誤差由於數據綁定)AG_E_PARSER_BAD_PROPERTY_VALUE [行:50的位置:45]

<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; 

結合不正常,但我甲肝e不知道爲什麼!我知道INotifyPropertyChanged不像WP7那樣安靜地工作於Silverlight 4.0。但我已經有了DependencyProperties。我還能爲此做些什麼?

感謝提前:)

回答

2

應用程序任務欄是一個有點奇怪的控制......看到這個帖子"Why application bar is not a FrameworkElement?"

我想是因爲應用程序任務欄是不是一個FrameworkElement的,你可以在它沒有數據綁定 - 類似德里克的回答Getting AG_E_PARSER_BAD_PROPERTY_VALUE while data binding in WP7 User control

我很抱歉地說,你可能只需要調整代碼隱藏的應用程序任務欄,而不是通過數據綁定 - 見Change applicationbar buttonicon at runtime

+0

- 我如何調整我t代碼?當我在MainPage.xaml.cs的Loaded事件中訪問這個愚蠢的控件(prevItem)時,我得到Null。你能解釋一下它在負載事件中怎麼會是空的? – TCM 2011-04-30 17:43:35

+0

查看我鏈接的問題中的答案 - 你不能使用名字 - 你總是需要使用數組索引訪問,比如'(IApplicationBarIconButton)ApplicationBar.Buttons [2]' - 可能不如數據綁定好,但你只需要笑並承擔責任。 – Stuart 2011-04-30 20:52:18

相關問題