如何在C#中将行为添加到ApplicationBarIconButton?
|
我正在尝试将行为添加到应用程序栏中。
在xaml中,它们看起来像:
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible=\"True\"
IsMenuEnabled=\"True\">
<shell:ApplicationBarIconButton x:Name=\"Save\"
IconUri=\"/resources/icons/appbar.check.rest.png\"
Text=\"Save\" />
<shell:ApplicationBarIconButton x:Name=\"Cancel\"
IconUri=\"/resources/icons/appbar.cancel.rest.png\"
Text=\"Cancel\" />
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<i:Interaction.Behaviors>
<Behaviors:ApplicationBarIconButtonCommand TextKey=\"Save\"
CommandBinding=\"{Binding SaveEventSetupCommand}\" />
<Behaviors:ApplicationBarIconButtonCommand TextKey=\"Cancel\"
CommandBinding=\"{Binding CancelEventSetupCommand}\" />
</i:Interaction.Behaviors>
对于多语言支持,我需要添加以下内容:
Text=\"{Binding Path=Localizedresources.lblCourse, Source={StaticResource LocalizedStrings}}\"
每个按钮。看来这无法在xaml中完成,因此需要使用代码。
该按钮添加在以下代码中:
ApplicationBarIconButton appBarSaveButton = new ApplicationBarIconButton(
new Uri(\"/resources/icons/appbar.check.rest.png\", UriKind.Relative))
{ Text = \"Test\" };
ApplicationBar.Buttons.Add(appBarSaveButton);
我只是不知道如何添加行为。这是我的起点:
WP7Contrib.View.Controls.Behaviors.ApplicationBarIconButtonCommand
ibc = new WP7Contrib.View.Controls.Behaviors.ApplicationBarIconButtonCommand
{ TextKey = \"Test\" };
基本上,如果有人愿意,我正在寻找一个有效的样本。
谢谢
没有找到相关结果
已邀请:
3 个回复
恋卡
并在底部的网格内:
参考文献: http://blog.humann.info/post/2010/08/27/How-to-have-binding-on-the-ApplicationBar.aspx http://www.codeproject.com/KB/windows-phone-7/CommandToAppBarWP7.aspx?display=Mobile
貉骂
主体与您的方案相同:创建行为,然后使用
注意:在上面的示例中,这是指视图的背后代码,而不是视图模型中的代码。
扫窟