Binding Text property with ApplicationBarIconButton in WP7

I want to bind a string to a text property in ApplicationBarIconButton in WP7. While doing this, I received an error message like

Set the property "Microsoft.Phone.Shell.ApplicationBarIconButton.Text" threw an exception.

Stacktrace:

in System.Reflection.RuntimeMethodInfo.InternalInvoke (Object obj, BindingFlags invokeAttr, binder, Object parameters [], CultureInfo, StackCrawlMark & ​​stackMark) in System.Reflection.RuntimePropertyInfo.InternalSetValue (PropertyInfo Object, ObjectProper ] index, StackCrawlMark & ​​stackMark) in System.Reflection.RuntimePropertyInfo.SetValue (Object obj, Object value, Object [] index) on MS.Internal.XamlMemberInfo.SetValue (target, object value) in MS.Internal .XamlManagedRuntimeRPInvokes.SetValue (XamlTypeToken inType, XamlQualifiedObject & inObj, XamlPropertyToken inProperty, XamlQualifiedObject & price) in MS.Internal.XcpImports.Application_LoadComponentNative (IntPtr pContext, IntPtr pComponent, UInt32 cUriStringLength, String uriString, UInt32 cXamlStrLength, Byte * pXamlStr, UInt32 cAs semblyStrLength, String assemblyStr) in MS.Internal.XcpImports.Application_LoadComponent (IManagedPeerBase componentAsDO, String resourceLocator, UnmanagedMemoryStream stream, UInt32 numBytesToRead, String assemblyString) in the System.Window.LocfunctionPlocompletion.Location .Controls.TimeSpanPickerPage.InitializeComponent () in Syncfusion.Phone.Tools.Controls.TimeSpanPickerPage..ctor () in System.Reflection.RuntimeConstructorInfo.InternalInvoke (RuntimeConstructorInfo rtci, BindingFlags invokeaf, CultureOndefender Subscriber, Boolean verifyAccess, StackCrawlMark & ​​stackMark) in System.Reflection.RuntimeConstructorInfo.InternalInvoke (Object obj, BindingFlags invokeAttr, binder binder, parameters Ob ject [], CultureInfo Culture, StackCrawlMark & ​​stackMark) in System.Activator.InternalCreateInstance (Type Type, Boolean nonPublic, StackCrawlMark & ​​stackMark) in System.Activator.CreateInstance (Type Type) in System.Windows.Navigation.PageHreadNesControlTegourceInvest userCallback, PageResourceContentLoaderAsyncResult result) in System.Windows.Navigation.PageResourceContentLoader. <> c_DisplayClass4.b_0 (Object arg) in System.Reflection.RuntimeMethodInfo.InternalInvoke (RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binding Binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, CheckMarklearklarkMecklarkl, AssemblyClecklark, AssemblyClecker System.Reflection.RuntimeMethodInfo.InternalInvoke (Object obj, BindingFlags invokeAttr, binder, Object [] parameters, CultureInfo culture, StackCrawlMark & ​​stackMark) in the System.Reflection.MethodBase.Invoke (Object obj, Object []) parameters in System.Dlegate .DynamicInvokeOne (Object [] args) in System.MulticastDelegate.DynamicInvokeImpl (Object [] args) in System.Delegate.DynamicInvoke (Object [] args) in System.Windows.Threading.DispatcherOperation.Invoke () in System.Windows.Threading .Di spatcher.Dispatch (DispatcherPriority priority) in System.Windows.Threading.Dispatcher.OnInvoke (object context) in System.Windows.Hosting.CallbackCookie.Invoke (Object [] args) in System.Windows.Hosting.DelegateWrapper.InternalInvoke (Object [ ] args) in System.Windows.RuntimeHost.ManagedHost.InvokeDelegate (IntPtr pHandle, Int32 nParamCount, ScriptParam [] pParams, ScriptParam & pResult)

Solution: ApplicationBar is a special element that is not implemented in Silverlight and cannot be used with data binding. You will need to directly update the Text property in C #. Peter Torr explains this here: Peter Torr Blog> Why are ApplicationBars not FrameworkElements?

+6
source share
2 answers

It seems to me that you already know the answer, one way or another, attached ApplicationBar data is not possible, you can create an application bar at runtime, although you can do something from there. ApplicationBarIconButton In Runtime

+7
source

Despite the fact that ApplicationBar is not a binding object, there are working commands for working with binding.

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

+3
source

Source: https://habr.com/ru/post/911916/


All Articles