WinPhone7 のコードでアプリケーション バーを作成しようとしています。それを行う XAML は次のようになります。
<PhoneApplicationPage.ApplicationBar>
<shellns:ApplicationBar Visible="True" IsMenuEnabled="True">
<shellns:ApplicationBar.Buttons>
<shellns:ApplicationBarIconButton IconUri="/images/appbar.feature.search.rest.png" />
</shellns:ApplicationBar.Buttons>
</shellns:ApplicationBar>
</PhoneApplicationPage.ApplicationBar>
だから私はC#でそれを書き直すだけだと思った:
var appbar = new ApplicationBar();
var buttons = new List<ApplicationBarIconButton>();
buttons.Add(new ApplicationBarIconButton(new Uri("image.png", UrlKind.Relative));
appbar.Buttons = buttons; //error CS0200: Property or indexer 'Microsoft.Phone.Shell.ApplicationBar.Buttons' cannot be assigned to -- it is read only
唯一の問題は、Buttons
プロパティに set アクセサーがなく、次のように定義されていることです。
public sealed class ApplicationBar {
//...Rest of the ApplicationBar class from metadata
public IList Buttons { get; }
}
C# ではなく XAML でこれを実行できるのはなぜですか? この構文を使用してオブジェクトを構築する特別な方法はありますか?
さらに重要なことに、コードでこれをどのように再現できますか?