Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding Text property with ApplicationBarIconButton in WP7

I want to bind the string to Text Property in ApplicationBarIconButton in WP7. While doing this, I got an error as

Set property 'Microsoft.Phone.Shell.ApplicationBarIconButton.Text' threw an exception.

StackTrace:

at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at System.Reflection.RuntimePropertyInfo.InternalSetValue(PropertyInfo thisProperty, Object obj, Object value, Object[] index, StackCrawlMark& stackMark) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) at MS.Internal.XamlMemberInfo.SetValue(Object target, Object value) at MS.Internal.XamlManagedRuntimeRPInvokes.SetValue(XamlTypeToken inType, XamlQualifiedObject& inObj, XamlPropertyToken inProperty, XamlQualifiedObject& inValue) at MS.Internal.XcpImports.Application_LoadComponentNative(IntPtr pContext, IntPtr pComponent, UInt32 cUriStringLength, String uriString, UInt32 cXamlStrLength, Byte* pXamlStr, UInt32 cAssemblyStrLength, String assemblyStr) at MS.Internal.XcpImports.Application_LoadComponent(IManagedPeerBase componentAsDO, String resourceLocator, UnmanagedMemoryStream stream, UInt32 numBytesToRead, String assemblyString) at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at Syncfusion.Phone.Tools.Controls.TimeSpanPickerPage.InitializeComponent() at Syncfusion.Phone.Tools.Controls.TimeSpanPickerPage..ctor() at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type) at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result) at System.Windows.Navigation.PageResourceContentLoader.<>c_DisplayClass4.b_0(Object args) at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Delegate.DynamicInvokeOne(Object[] args) at System.MulticastDelegate.DynamicInvokeImpl(Object[] args) at System.Delegate.DynamicInvoke(Object[] args) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority) at System.Windows.Threading.Dispatcher.OnInvoke(Object context) at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args) at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args) at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

Solution: The ApplicationBar is a special element that is not implemented in Silverlight and cannot be used with databinding. You'll have to directly update the Text property in C#. Peter Torr explains it here: Peter Torr's Blog > Why are the ApplicationBar objects not FrameworkElements?

like image 373
Ponmalar Avatar asked Mar 29 '12 07:03

Ponmalar


2 Answers

It seems to me you already know the answer, anyhow binding data the ApplicationBar is not possible, you can create the application bar at runtime though, you might be able to do something from there. ApplicationBarIconButton At Runtime

like image 74
Alaa.Ali Avatar answered Oct 17 '22 03:10

Alaa.Ali


Although the ApplicationBar is not a bindable object, there are workarouds to make binding work.

One, is the ApplicationBarBehavior from the Cimbalino Windows Phone Toolkit (you can get it from NuGet)!

like image 3
Pedro Lamas Avatar answered Oct 17 '22 03:10

Pedro Lamas