This is my code of ApplicationBar (The code which is causing error due to databinding)
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" >
<shell:ApplicationBarIconB开发者_JAVA百科utton 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>
These are my properties in code-behind :-
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);
}
}
In the construtor I have this line:-
this.DataContext = this;
The binding is not working properly but I have no idea Why! I know INotifyPropertyChanged doesn't quiet work well with WP7 as Silverlight 4.0. But I already have DependencyProperties. What more can I do for this?
Thanks in advance :)
ApplicationBar is a bit odd as a control... see this post "Why application bar is not a FrameworkElement?"
I think because the ApplicationBar is not a FrameworkElement you can't data bind within it - similar to Derek's answer to Getting AG_E_PARSER_BAD_PROPERTY_VALUE while data binding in WP7 User control
I'm sorry to say that you may just have to adjust the ApplicationBar in CodeBehind rather than through databinding - see Change applicationbar buttonicon at runtime
精彩评论