2012-03-29 26 views
6

我想將該字符串綁定到WP7中的ApplicationBarIconButton中的文本屬性。 雖然這樣做,我得到一個錯誤,因爲使用WP7中的ApplicationBarIconButton綁定文本屬性

設置屬性'Microsoft.Phone.Shell.ApplicationBarIconButton.Text'拋出一個異常。

堆棧跟蹤:

在System.Reflection.RuntimeMethodInfo.InternalInvoke(對象OBJ, 的BindingFlags invokeAttr,粘結劑粘結劑,對象[]參數, CultureInfo的文化,StackCrawlMark & stackMark) 在的System.Reflection .RuntimePropertyInfo.InternalSetValue(PropertyInfo thisProperty,Object obj,Object value,Object [] index, StackCrawlMark & stackMark) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj,Object值,在MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken法菜單, XamlQualifiedObject & inObj,XamlPropertyToken inProperty, XamlQualifiedObject & inValue) 對象[]索引) 在MS.Internal.XamlMemberInfo.SetValue(對象目標,對象的值) 在MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr的 pContext,IntPtr的P-分量,UInt32的cUriStringLength,字符串 uriString中,UInt32的cXamlStrLength,BYTE * pXamlStr,UInt32的 cAssemblyStrLength,字符串assemblyStr) 在MS.Internal.XcpImports.Application_LoadComponent(IManagedPeerBase componentAsDO ,String resourceLocator,UnmanagedMemoryStrea米流, UInt32的numBytesToRead,字符串assemblyString) 在System.Windows.Application.LoadComponent(對象部件,烏里resourceLocator) 在Syncfusion.Phone.Tools.Controls.TimeSpanPickerPage.InitializeComponent() 在Syncfusion.Phone.Tools.Controls .TimeSpanPickerPage..ctor() 在System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo RTCI,的BindingFlags invokeAttr,粘結劑粘結劑,對象參數, CultureInfo的文化,布爾isBinderDefault,裝配呼叫者,布爾 verifyAccess,StackCrawlMark & stackMark) 在System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr,B因德爾粘合劑,在System.Activator.InternalCreateInstance(類型類型,布爾非公開,StackCrawlMark & stackMark) 對象[]參數, CultureInfo的文化,StackCrawlMark & stackMark) 在System.Activator.CreateInstance(類型類型) 在System.Windows .Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback,PageResourceContentLoaderAsyncResult result) at System.Windows.Navigation.PageResourceContentLoader。 <> C_ DisplayClass4.b _0(對象 參數) 在System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi,對象OBJ,的BindingFlags invokeAttr,粘結劑粘結劑,對象 參數,CultureInfo的文化,布爾isBinderDefault,裝配 呼叫者,Boolean verifyAccess,StackCrawlMark & stackMark) at System.Reflection.RuntimeMethodInfo。InternalInvoke在System.Delegate.DynamicInvokeOne在System.Reflection.MethodBase.Invoke(對象OBJ, 的BindingFlags invokeAttr,粘結劑粘結劑,對象[]參數, CultureInfo的文化,StackCrawlMark & stackMark) (對象OBJ,對象[]參數) 在System.MulticastDelegate.DynamicInvokeImpl(對象[]參數) 在System.Windows(對象[]參數) 在System.Delegate.DynamicInvoke(對象[]參數) 在System.Windows.Threading.DispatcherOperation.Invoke() .Threading.Dispatcher.Dispatch(DispatcherPriority priority) at System.Windows.Threading.Dispatcher.OnInvoke(Object context) at System.Windows.Hosting。在System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount,ScriptParam [] pParams,System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object [] args) 上調用CallbackCookie.Invoke(Object [] args) ScriptParam & pResult)

解決方案:的應用程序任務是未在Silverlight實現,並且不能與數據綁定使用的特殊元件。您必須直接更新C#中的Text屬性。 Peter Torr在這裏解釋它:Peter Torr的博客>Why are the ApplicationBar objects not FrameworkElements?

回答

7

在我看來,你已經知道答案了,無論如何綁定數據ApplicationBar是不可能的,你可以在運行時創建應用程序欄,但是,你也許能夠做到一些東西從那裏。 ApplicationBarIconButton At Runtime

+1

不是這樣,我在這裏問了問題,並繼續搜索時間找到答案,所以張貼在這裏。謝謝。 – Ponmalar 2012-03-29 08:29:32

+0

很高興你做了:)。 你應該考慮運行時創建。 – 2012-03-29 08:38:41

+1

是的,我得到了我的預期。謝謝。 – Ponmalar 2012-03-29 09:20:41

相關問題