這是我的應用程序任務的代碼(該代碼,這是造成誤差由於數據綁定)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。我還能爲此做些什麼?
感謝提前:)
- 我如何調整我t代碼?當我在MainPage.xaml.cs的Loaded事件中訪問這個愚蠢的控件(prevItem)時,我得到Null。你能解釋一下它在負載事件中怎麼會是空的? – TCM 2011-04-30 17:43:35
查看我鏈接的問題中的答案 - 你不能使用名字 - 你總是需要使用數組索引訪問,比如'(IApplicationBarIconButton)ApplicationBar.Buttons [2]' - 可能不如數據綁定好,但你只需要笑並承擔責任。 – Stuart 2011-04-30 20:52:18