1

Closed

App start fails if Binding is used for Text in SelectedPivotItemChangedTrigger

description

This fails:appBarUtils:AppBarButton IconUri="/Assets/appbar.settings.png" Text="{Binding Loc.AppBarSettings}" Command="{Binding ShowSettings}"but when changed the line to this, it works:appBarUtils:AppBarButton IconUri="/Assets/appbar.settings.png" Text="abcd" Command="{Binding ShowSettings}"fixed it myself by setting dummy text here: public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(AppBarItemBase), new PropertyMetadata("empty", TextPropertyChanged));and changing the constructor like this: public AppBarButton() { _applicationBarItem = new ApplicationBarIconButton(); ChangeText(); // also made it protected SubscribeClickEvent(); }
Closed May 26, 2013 at 5:45 AM by allenlooplee
Fixed in 2.3

comments

Necroman wrote Nov 18, 2012 at 6:01 PM

edit, third update, it looks like pasting code directly from VS2012 causes entering only white symbols

Necroman wrote Nov 18, 2012 at 6:04 PM

fourth try, apparently I cannot use XAML code when submitting bugs

allenlooplee wrote May 25, 2013 at 2:00 PM

Hi there,

There's a sample using SelectedPivotItemChangedTrigger and setting Text of AppBarButton to a string rather than binding, see DynamicAppBarPivotPage.xaml. But it runs fine. So I think it doesn't repro here.

allenlooplee wrote May 26, 2013 at 1:59 AM

Oops, I mistook your words. So when you set the Text with binding, it throws; while you set the Text to plain string, it works. Yes, I got this reproed in my code. This is because when adding an app bar button to an app bar, the latter one will check to see if the former one has its properties set correctly. Specifically, the IconUri should be a valid relative path, and the Text should be a valid string. If these don't meet, then it throws.

Due to how XAML works, setting the Text to a plain string happens before the AppBarButton's construction, so when adding the app bar button to the app bar, the Text already has a correct value. But setting the Text with data binding happens after the AppBarButton's construction, so the app bar finds the Text of the app bar button to be added is empty, and hence the exception.

Thanks for your fix. I'll apply it, and you'll see it in the next release.

Necroman wrote May 26, 2013 at 6:26 PM

Yes, that's what I meant. I already fixed it myself in the downloaded source code, good to have it fixed in the official version as well. You should probably check the other properties too, whether everything works fine when databindign si used.