2

我有一个有点令人抓狂的问题,只是试图让 Silverlight Pivot Control 开箱即用。

当我将所有内容连接在一起时,我在 JavaScript 错误中看到了这个堆栈跟踪:

Unhandled Error in Silverlight Application Set property 'System.Windows.FrameworkElement.Style' threw an exception. [Line: 9 Position: 35]   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at VehiclePivotViewer.MainPage.InitializeComponent()
   at VehiclePivotViewer.MainPage..ctor(IDictionary`2 initParams)
   at VehiclePivotViewer.App.Application_Startup(Object sender, StartupEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

我实际上下载了一个帮助程序库以进一步研究该异常,看起来MainPage.xaml 标记很难处理,即使它看起来都是有效的。


如果它有帮助,我在下面列出了我为设置它所采取的步骤。

  1. 创建一个新的 MVC3 Web 应用程序
  2. 在同一解决方案中创建一个 Silverlight 4 应用程序项目,并将其添加到 Web 项目中
  3. 添加五个System.Windows.Pivot程序集引用
  4. 将控件添加到我的 MainPage.xaml

    <Grid x:Name="LayoutRoot" Background="White">
        <Pivot:PivotViewer x:Name="Viewer" />
    </Grid>
    

  5. 连接集合 URL:Viewer.LoadCollection(initParams["CollectionUrl"], null);

  6. 在视图中设置适当的值:

`

<div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
        <param name="source" value="ClientBin/xxxPivotViewer.xap"/>
        <param name="onError" value="onSilverlightError" />
        <param name="background" value="white" />
        <param name="minRuntimeVersion" value="4.0.50826.0" />
        <param name="autoUpgrade" value="true" />
        <param name="enableHtmlAccess" value="true" />
          <param name="initParams" value="collectionUrl=@ViewBag.CollectionUrl %>" />
        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
            <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/>
        </a>
    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>

`

有人有什么想法或建议吗?我对 Silverlight 非常陌生,我有点想把我的头发拉出来。

4

2 回答 2

0

我注意到我只使用我的两台 Visual Studio 开发机器中的一台时遇到了同样的问题。有问题的机器可能安装了一些错误版本的 Silverlight 依赖项,或者缺少一些重要的东西。全新安装 VS 2010 和所有 Silverlight 开发工具以及 Pivot Control 解决了这个问题。因此,对于碰巧遇到此帖子的任何人,此错误可能是由不正确/不完整的 Silverlight/Pivot 开发环境引起的。

需要的工具是:

Visual Studio 2010。在Dreamspark获得免费的学术版本

Silverlight 4 VS 2010 工具

Silverlight 4 工具包

Silverlight 开发人员运行时

于 2011-12-13T04:06:00.323 回答
0

看起来您在 @ViewBag.CollectionUrl 前面缺少 <%。

于 2011-03-01T23:49:20.283 回答