C# 应用程序栏绑定Windows Phone
无法绑定ApplicationBar,我尝试了:C# 应用程序栏绑定Windows Phone,c#,xaml,binding,windows-phone,C#,Xaml,Binding,Windows Phone,无法绑定ApplicationBar,我尝试了: <phone:PhoneApplicationPage.ApplicationBar> <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True"> <shell:ApplicationBarIconButton x:Name="btnTest" IconUri="/Assets/Ap
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton
x:Name="btnTest"
IconUri="/Assets/AppBar/appbar.add.rest.png"
Text="{Binding MyBtnText}" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
资料来源:
或者从C后面的代码构建ApplicationBar
资料来源:
资料来源:
或者从C后面的代码构建ApplicationBar
资料来源:
ApplicationBar不是DependencyObject,不支持绑定。即使您只想使用AppBar本地化的绑定,而不使用与VIEW模型同步的动作或自动启用,并结束移动整个应用程序条设置到代码后方,您应该考虑使用XML中AppBar赋予您更大灵活性的库。例如,参见或。还有其他开放源代码项目允许对AppBar进行绑定 样本:
<bar:BindableApplicationBarButton
Text="{Binding IconButtonText}"
IconUri="{Binding IconUri, FallbackValue=/Icons/Dark/appbar.add.rest.png}"
IsEnabled="{Binding ButtonIsEnabled}" />
ApplicationBar不是DependencyObject,不支持绑定。即使您只想使用AppBar本地化的绑定,而不使用与VIEW模型同步的动作或自动启用,并结束移动整个应用程序条设置到代码后方,您应该考虑使用XML中AppBar赋予您更大灵活性的库。例如,参见或。还有其他开放源代码项目允许对AppBar进行绑定 样本:
<bar:BindableApplicationBarButton
Text="{Binding IconButtonText}"
IconUri="{Binding IconUri, FallbackValue=/Icons/Dark/appbar.add.rest.png}"
IsEnabled="{Binding ButtonIsEnabled}" />
// Build a localized ApplicationBar
private void BuildLocalizedApplicationBar()
{
// Set the page's ApplicationBar to a new instance of ApplicationBar.
ApplicationBar = new ApplicationBar();
// Create a new button and set the text value to the localized string from AppResources.
ApplicationBarIconButton appBarButton =
new ApplicationBarIconButton(new
Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
appBarButton.Text = AppResources.Reset;
ApplicationBar.Buttons.Add(appBarButton);
// Create a new menu item with the localized string from AppResources.
ApplicationBarMenuItem appBarMenuItem =
new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
ApplicationBar.MenuItems.Add(appBarMenuItem);
}
<bar:BindableApplicationBarButton
Text="{Binding IconButtonText}"
IconUri="{Binding IconUri, FallbackValue=/Icons/Dark/appbar.add.rest.png}"
IsEnabled="{Binding ButtonIsEnabled}" />