在 PC 上运行,在 Mac 上崩溃
是的,这里是场景:
我创建了一个名为“DiaryPage”的类,它继承自 Canvas
我创建了一个名为“DiaryControl”的用户控件,其中包含“DiaryPage”元素。页面的高度、宽度等都是数据绑定的,如下所示:
Width="{Binding DataContext.Info.Booktype, ConverterParameter=CoverWidth, Converter={StaticResource BookTypeToDimentionsConverter}, FallbackValue=490, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType=UserControl}}"
现在,它在运行 silverlight 5 的 PC 上完美运行,但在 Mac 上运行的相同代码会产生以下异常:
在 System.Windows.Application.LoadComponent(Object component, Uri 资源定位器)
在 Life.Views.Book.Framework.DiaryControl.InitializeComponent()
在 Life.Views.Book.Framework.DiaryControl..ctor() 找不到方法:“Void System.Windows.FrameworkElement.add_DataContextChanged(System.Windows.DependencyPropertyChangedEventHandler)”。
在System.Windows.Application.LoadComponent(对象组件,Uri资源定位器)
在 Life.Views.Book.Framework.DiaryControl.InitializeComponent()
在 Life.Views.Book.Framework.DiaryControl..ctor() 上对与指定绑定约束匹配的类型“Life.Views.Book.Framework.DiaryPageControl”的构造函数的调用引发了异常。 对与指定绑定约束匹配的“Life.Views.Book.Framework.DiaryPageControl”类型的构造函数的调用引发了异常。 [Line: 327 Position: 28]
[Line 327] 对应于上面指定的 Width 绑定
有什么想法吗?
在我的 DiaryPage 类中,我附加了一个 datacontextchanged 侦听器,如下所示:
DataContextChanged += new DependencyPropertyChangedEventHandler(DiaryPageControl_DataContextChanged);
void DiaryPageControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if(DataContext != null && DataContext.GetType()== typeof(Page))
LoadContent();
}
正如我所说,在 Windows 上很有用(测试了 5 台电脑),但在 mac 上抛出异常(好吧,我尝试过的那个)
Right, so here the scenario:
I've created a class called "DiaryPage" that inherites from Canvas
I've created a usercontrol called "DiaryControl" that contains "DiaryPage" elements. The page's height, width and so on are all databound like so :
Width="{Binding DataContext.Info.Booktype, ConverterParameter=CoverWidth, Converter={StaticResource BookTypeToDimentionsConverter}, FallbackValue=490, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType=UserControl}}"
Now, It works perfectly on pc, running silverlight 5 BUT the same code running on a mac produces the following exception:
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Life.Views.Book.Framework.DiaryControl.InitializeComponent()
at Life.Views.Book.Framework.DiaryControl..ctor()Method not found: 'Void System.Windows.FrameworkElement.add_DataContextChanged(System.Windows.DependencyPropertyChangedEventHandler)'.
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Life.Views.Book.Framework.DiaryControl.InitializeComponent()
at Life.Views.Book.Framework.DiaryControl..ctor()The invocation of the constructor on type 'Life.Views.Book.Framework.DiaryPageControl' that matches the specified binding constraints threw an exception.
The invocation of the constructor on type 'Life.Views.Book.Framework.DiaryPageControl' that matches the specified binding constraints threw an exception. [Line: 327 Position: 28]
[Line 327] corresponds to the Width binding specified above
Any ideas?
In my DiaryPage class i have a datacontextchanged listener attached like so:
DataContextChanged += new DependencyPropertyChangedEventHandler(DiaryPageControl_DataContextChanged);
void DiaryPageControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if(DataContext != null && DataContext.GetType()== typeof(Page))
LoadContent();
}
As I said, works a charm on windows (tested 5 pc's), but throws exception on mac (well, the one that I've tried)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Silverlight应该在 Mac 和 Windows PC 上以完全相同的方式工作。这听起来像是一个错误。您可能需要在 Microsoft Connect 网站上报告此问题。为了解决您眼前的问题,您只需要做一些探索性工作来找到框架中不适合您的部分并避免它!
另一点...确保 Mac 安装了最新的 Silverlight 版本,您正在那里使用相对较新的框架功能。
Silverlight should work exactly the same way on Mac and Windows PCs. This sounds like a bug. You might want to report it on the Microsoft Connect site. To solve your immediate issue you are just going to have to do a bit of exploratory work to find the part of the framework which is not working for you and avoid it!
One other point ... make sure the Mac has the latest Silverlight version installed, you are using a relatively new framework feature there.