Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8254337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:09:17+00:00 2026-06-08T01:09:17+00:00

I am using Phone7.Fx R1 The following works. The system does not react when

  • 0

I am using Phone7.Fx R1

The following works. The system does not react when a user presses the button. This means, than there is no reaction if Stop Game is pressed without a game has been started and vice versa.

However the button looks active. I am aware that I can bind the IsEnabled to a different property, but I would like it to bind to NewGameCanExecute and StopGameCanExecute. Is this possible?

Some XAML code:

<Preview:BindableApplicationBarIconButton Command="{Binding NewGame}" IconUri="/images/icons/appbar.add.rest.png" Text="New game" />
        <Preview:BindableApplicationBarIconButton Command="{Binding StopGame}" IconUri="/images/icons/appbar.stop.rest.png" Text="Stop game" />

And the relay commands:

public RelayCommand NewGame { get; private set; }
public RelayCommand StopGame { get; private set; }

//Constructor
NewGame = new RelayCommand(NewGameExecute, NewGameCanExecute);
StopGame = new RelayCommand(StopGameExecute, StopGameCanExecute);

void NewGameExecute()
{
    _gameStarted = true;
    _gameControlModel.StartNewGame();
    StopGame.RaiseCanExecuteChanged();
}

bool NewGameCanExecute()
{
    return !_gameStarted;
}

void StopGameExecute()
{      
    _gameControlModel.StopGame();
    _gameStarted = false;
    NewGame.RaiseCanExecuteChanged();
}

bool StopGameCanExecute()
{
    return _gameStarted;
}

Couple of questions and answers:

Q: Have you tried to set a breakpoint in the CanExecute functions to see if it gets called?

A: Yes. It does get called, but the icon is not grayed out, eventhough false is returned.
The Execute method is not executed, if the CanExecute method returns false. But I want the icon to be grayed out like a normal button.

SOLUTION

I spend some time and came up with a solution, which can be found here:
http://pastebin.com/MM75xACj

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:09:18+00:00Added an answer on June 8, 2026 at 1:09 am

    SOLUTION

    I spend some time and came up with a solution and edited the applicationbariconbutton class.

    namespace Phone7.Fx.Controls
    {
        public class BindableApplicationBarIconButton : FrameworkElement, IApplicationBarIconButton
        {
            public int Index { get; set; }
    
            public static DependencyProperty CommandProperty = DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(BindableApplicationBarIconButton), new PropertyMetadata(null, OnCommandPropertyChanged));
            private static void OnCommandPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                if (e.NewValue != e.OldValue)
                {
                    ((BindableApplicationBarIconButton)d).Command = (ICommand)e.NewValue;
                }
            }
    
            public ICommand Command
            {
                get { return (ICommand)GetValue(CommandProperty); }
                set {
                        Command.CanExecuteChanged -= ValueOnCanExecuteChanged;
                    SetValue(CommandProperty, value);
                    Command.CanExecuteChanged += ValueOnCanExecuteChanged;
                }
            }
    
            private void ValueOnCanExecuteChanged(object sender, EventArgs eventArgs)
            {
                ICommand commandSender = sender as ICommand;
                if(commandSender != null)
                {IsEnabled = commandSender.CanExecute(null);}
            }
    
            public static readonly DependencyProperty CommandParameterProperty =
                DependencyProperty.RegisterAttached("CommandParameter", typeof(object), typeof(BindableApplicationBarIconButton), new PropertyMetadata(null, OnCommandParameterPropertyChanged));
            private static void OnCommandParameterPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                var invokeCommand = d as BindableApplicationBarIconButton;
                if (invokeCommand != null)
                {
                    invokeCommand.SetValue(CommandParameterProperty, e.NewValue);
                }
            }
            public object CommandParameter
            {
                get { return GetValue(CommandParameterProperty); }
                set
                {
                    SetValue(CommandParameterProperty, value);
                }
            }
    
    
            public static readonly DependencyProperty CommandParameterValueProperty =
              DependencyProperty.RegisterAttached("CommandParameterValue", typeof(object), typeof(BindableApplicationBarIconButton), null);
            public object CommandParameterValue
            {
                get
                {
                    var returnValue = GetValue(CommandParameterValueProperty);
                    return returnValue;
                }
                set { SetValue(CommandParameterValueProperty, value); }
            }
    
            public static readonly DependencyProperty IsEnabledProperty =
                DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(BindableApplicationBarIconButton), new PropertyMetadata(true, OnEnabledChanged));
    
            private static void OnEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                if (e.NewValue != e.OldValue)
                {
                    ((BindableApplicationBarIconButton)d).Button.IsEnabled = (bool)e.NewValue;
                }
            }
    
            public static readonly DependencyProperty TextProperty =
                DependencyProperty.RegisterAttached("Text", typeof(string), typeof(BindableApplicationBarIconButton), new PropertyMetadata(OnTextChanged));
    
            public new static readonly DependencyProperty VisibilityProperty =
               DependencyProperty.RegisterAttached("Visibility", typeof(Visibility), typeof(BindableApplicationBarIconButton), new PropertyMetadata(OnVisibilityChanged));
    
            private static void OnVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                if (e.NewValue != e.OldValue)
                {
                    var button = ((BindableApplicationBarIconButton)d);
                    BindableApplicationBar bar = button.Parent as BindableApplicationBar;
    
                    bar.Invalidate();
                }
            }
    
            public new Visibility Visibility
            {
                get { return (Visibility)GetValue(VisibilityProperty); }
                set { SetValue(VisibilityProperty, value); }
            }
    
            private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                if (e.NewValue != e.OldValue)
                {
                    ((BindableApplicationBarIconButton)d).Button.Text = e.NewValue.ToString();
                }
            }
    
            public ApplicationBarIconButton Button { get; set; }
    
            public BindableApplicationBarIconButton()
            {
                Button = new ApplicationBarIconButton();
                Button.Text = "Text";
                Button.Click += ApplicationBarIconButtonClick;
            }
    
            void ApplicationBarIconButtonClick(object sender, EventArgs e)
            {
                if (Command != null && CommandParameter != null)
                    Command.Execute(CommandParameter);
                else if (Command != null)
                    Command.Execute(CommandParameterValue);
                if (Click != null)
                    Click(this, e);
            }
    
            public bool IsEnabled
            {
                get { return (bool)GetValue(IsEnabledProperty); }
                set { SetValue(IsEnabledProperty, value); }
            }
    
            public string Text
            {
                get { return (string)GetValue(TextProperty); }
                set { SetValue(TextProperty, value); }
            }
    
            public event EventHandler Click;
    
            public Uri IconUri
            {
                get { return Button.IconUri; }
                set { Button.IconUri = value; }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing the following: [self.parentViewController dismissModalViewControllerAnimated:YES] This code fails using the Simulator but works
Is there a possibility to take a picture using phone's camera without user interaction?
UPDATE Got it to work by using has_and_belongs_to_many Anyone know why this works ?
i am using zend paginator in my app.pagination works well but i get this
Does anyone have any experience with this? I have been using python 3.2 for
I'm using a phone API called Twilio and it does text to voice. I'm
I am using this code phone calling from iPhone its calling directly to particular
Using this tutorial: http://www.c-sharpcorner.com/uploadfile/UrmimalaPal/creating-a-windows-phone-7-application-consuming-data-using-a-wcf-service/ I have created sample/hello world application on the windows phone
I have created an application that creates notifications, using the following code: // notification
I following this article for sending SMS it is a winform application.. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.