Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

When you work with the ApplicationBar in Windows Phone 7, you notice very fast that it is not quite a component like the others. For example, the ApplicationBarIconButton element is not a dependency object, which causes issues because it is not possible to add attached properties to it.

Read the rest of this entry ยป

Print | posted on Tuesday, June 8, 2010 11:06 AM

Feedback

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by timheuer at 6/8/2010 1:02 PM Gravatar
Is the app bar opacity set to something greater than 0?

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Laurent Bugnion at 6/8/2010 8:13 PM Gravatar
Hey Tim,

The Opacity is left untouched. Would that make a difference?

Cheers,
Laurent

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Grumpydev at 6/9/2010 1:35 AM Gravatar
Would it not be "nicer" to update the text box binding using a simple behaviour? Something like this:

using System;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace SLTextBoxBehaviorTest
{
public class UpdateSourceTriggerPropertyChangedBehavior : Behavior<TextBox>
{
protected override void OnAttached()
{
base.OnAttached();

this.AssociatedObject.TextChanged += TextChanged;
}

protected override void OnDetaching()
{
base.OnDetaching();

this.AssociatedObject.TextChanged -= TextChanged;
}

protected void TextChanged(object sender, TextChangedEventArgs e)
{
var binding = this.AssociatedObject.GetBindingExpression(TextBox.TextProperty);

if (binding == null)
return;

if (binding.ParentBinding.Mode != System.Windows.Data.BindingMode.TwoWay)
return;

binding.UpdateSource();
}
}
}

( http://codepaste.net/7b5pvo )

That should make it behave the same way as setting UpdateSourceTrigger to PropertyChanged in WPF.

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Mark Monster at 6/13/2010 3:57 AM Gravatar
Nice approach to overcome the ApplicationBar button problem. I've also experienced this problem, and used a solution where I create the buttons from codebehind, and keep a reference in there. It's also not perfect, but I think the ApplicationBar will probably need more improvements. I would like to see the ability to put in at least a vectorbased icon (hopefully xaml).

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Matt Casto at 8/7/2010 1:22 PM Gravatar
This is exactly what I was looking for. Thanks for investigating and suggesting work-arounds.

If these controls aren't updated to work like regular buttons by the final release of the tools, I'll be extremely disappointed. I'm really bummed that I can't use EventToCommand on them.

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Laurent at 8/7/2010 3:02 PM Gravatar
We've been talking to the team about it, and unfortunately it is not as easy as it looks, because the App bar is a system-wide component that is getting wrapped in Silverlight. Still, I agree, having a clean control/routed events implementation would be great.

Cheers,
Laurent

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Matt Casto at 8/7/2010 3:09 PM Gravatar
Even if these issues can't be resolved, at the very least some more properties should be available, like Visibility and possibly NavigateUri (or make a ApplicationBarLinkButton).

In any case, without commanding its messaging to the resume! ;-)

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Sam Judson at 8/24/2010 9:42 PM Gravatar
The second issue here is really annoying me. I have 3 textboxes and I don't know how to tell which one has the focus to make sure its databinding is up to date. I don't really want to have to have to manually update all three of them else it kind of defeats the purpose of data binding!

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by Sam Judson at 8/25/2010 2:11 AM Gravatar
Found a solution. You use the FocusManager property to get the control with the current focus.


object focusObj = FocusManager.GetFocusedElement();
if (focusObj != null && focusObj is TextBox)
{
var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty);
binding.UpdateSource();
}

Sam

# re: Two small issues with Windows Phone 7 ApplicationBar buttons (and workaround)

left by James at 4/12/2011 9:50 AM Gravatar
Q1. Use "sender as" is a alternative way to get instance, ex:
(sender as ApplicationBarIconButton).IsEnabled = false;
Comments have been closed on this topic.