3

ビヘイビアを使用してアプリケーションバーにアイテムを追加しようとしています。

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

基本的に、誰かが義務付けられるのであれば、私は実用的なサンプルを探しています。

ありがとう

4

3 に答える 3

2

マットの答えに基づいて、これは私の解決策です:

xamlページの上部にこれを追加します。

xmlns:Preview="clr-namespace:Phone7.Fx.Preview;assembly=Phone7.Fx.Preview"

下部のグリッド内にあります。

    <Preview:BindableApplicationBar x:Name="AppBar" BarOpacity="1.0" IsVisible="{Binding IsBarVisible}" >
        <Preview:BindableApplicationBarIconButton 
            Command="{Binding SaveCommand}"
            Text="{Binding Path=Localizedresources.lblSave, Source={StaticResource LocalizedStrings}}" 
            IconUri="/resources/icons/appbar.check.rest.png" />
        <Preview:BindableApplicationBarIconButton 
            Command="{Binding CancelCommand}"
            Text="{Binding Path=Localizedresources.lblCancel, Source={StaticResource LocalizedStrings}}" 
            IconUri="/resources/icons/appbar.cancel.rest.png" />
    </Preview:BindableApplicationBar>

参照: 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

于 2011-04-17T14:48:14.347 に答える
0

すでに作成したXAMLのリソースにのTextプロパティを指定することはできません。ApplicationBarIconButtonビヘイビアーを作成してコードに添付するには、次のようなコードを使用します(現在作業中のアプリから変更)。

((ApplicationBarIconButton)this.ApplicationBar.Buttons[0].Text = Strings.NewContact;
var newBehavior = new ApplicationBarButtonNavigation
{
    ButtonText = Strings.NewContact,
    NavigateTo = new Uri("/views/ContactView.xaml", UriKind.RelativeOrAbsolute),
};
Interaction.GetBehaviors(this).Add(newBehavior);

原則はシナリオでも同じです。動作を作成してから、Interaction.GetBehaviors(this).Add(yourBehavior);

注:上記の例では、これはビューのコードビハインドを参照しており、ビューモデルには含まれていません。

于 2011-04-15T12:36:32.107 に答える
0

http://blog.humann.info/post/2010/08/27/How-to-have-binding-on-the-ApplicationBar.aspxのラッパーを使用して、ApplicationBarをバインド可能にすることができます。

コマンドの追加についてはよくわかりませんが、これは同じ手法で可能です。

于 2011-04-15T12:39:45.163 に答える