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マークアップはすべて有効であるように見えますが、苦労しているようです。
役立つ場合は、すべてを設定するために行った手順を以下に示します。
- 新しいMVC3Webアプリケーションを作成します
- 同じソリューションでSilverlight4アプリケーションプロジェクトを作成し、それをWebプロジェクトに追加します
System.Windows.Pivot
5つのアセンブリ参照を追加しますMainPage.xamlにコントロールを追加します
<Grid x:Name="LayoutRoot" Background="White"> <Pivot:PivotViewer x:Name="Viewer" /> </Grid>
コレクションのURLを配線します。
Viewer.LoadCollection(initParams["CollectionUrl"], null);
- ビューで適切な値を設定します。
`
<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に非常に慣れていないので、ちょっと髪の毛を抜いています。