在 PC 上运行,在 Mac 上崩溃

发布于 2024-12-27 03:13:31 字数 1664 浏览 1 评论 0原文

是的,这里是场景:

我创建了一个名为“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光与爱终年不遇 2025-01-03 03:13:31

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文