wpf – XAML如何设置只读CLR属性?
发布时间:2020-12-14 05:52:18 所属栏目:Windows 来源:网络整理
导读:我正在尝试在WinPhone7的代码中创建一个应用程序栏.执行此操作的XAML如下所示: PhoneApplicationPage.ApplicationBar shellns:ApplicationBar Visible="True" IsMenuEnabled="True" shellns:ApplicationBar.Buttons shellns:ApplicationBarIconButton IconU
我正在尝试在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; } } 为什么在XAML而不是C#中可以做到这一点?是否有使用此语法构造对象的特殊方法? 更重要的是,如何在代码中重新创建它? 解决方法
appbar.Buttons.Add(new ApplicationBarIconButton(new Uri(“image.png”,UrlKind.Relative));
直接添加到Buttons属性. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-phone-7 – monodroid,WP7和silverlight的单一代码
- Xaml无法创建“X”的实例
- 什么是Windows上使用的GS寄存器?
- Windows BAT:测试特定文件是否为空
- Windows10 下利用Hyper-V安装CentOS系统
- 应用程序无法正常启动0xc000007b解决方法
- 如何使用Windows API以编程方式调整窗口大小并移动窗口?
- zfs – Windows Server 2016群集磁盘的LIO iSCSI目标 – 设
- windows – 使用GRUB / GRUB2来PXE引导操作系统映像
- windows-7 – 激活Windows虚拟机进行测试?好坏?
推荐文章
站长推荐
热点阅读