我想在WinPhone7的代码中创建一个应用程序栏。 ,做它的XAML是这样的:XAML如何设置只读CLR属性?
<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; }
}
这是怎么来的,可以在XAML而不是C#?有没有一种特殊的方式来使用这种语法构造对象?
更重要的是,我该如何在代码中重新创建它?
卫生署!感谢那。 – 2010-04-12 23:58:42