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

  • Home
  • SEARCH
  • 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 3334116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:52:12+00:00 2026-05-17T23:52:12+00:00

Short explanation Button.CommandProperty is bound to SomeObject.SomeCommand property of the ViewModel. When SomeCommand property

  • 0

Short explanation

Button.CommandProperty is bound to SomeObject.SomeCommand property of the ViewModel. When SomeCommand property of SomeObject is set to null or entire SomeObject property is set to null, this button remains enabled. How can the button be disabled under this circumstances?

Detailed explanation

I am creating application using MVVM, which behaves like a browser:
Main view_model (which corresponds to main window as view) has a list of Workspace view_models. Each Workspace view_model corresponds to TabPage in windows’s TabControl.
Main view_model has CurrentWorkspace property which corresponds currently active TabPage.

In main window where is a toolbar with buttons, which utilizes commands provided by the CurrentWorkspace. For example, access to reloading workspace data is realized as:

<Button Name="btReload" Content="Reload" 
        Command="{Binding Path=CurrentWorkspace.ReloadCommand, UpdateSourceTrigger=PropertyChanged}"/>

I tried to accomplish the task of button disabling by creating DataTriggers, but it seems that triggers works only first time and no more:

<Button Name="btReload" Content="Reload" 
        Command="{Binding Path=CurrentWorkspace.ReloadCommand, UpdateSourceTrigger=PropertyChanged}">
    <Button.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=CurrentWorkspace, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
                     <Setter Property="dxb:BarButtonItem.IsEnabled" Value="False"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=CurrentPage.CurrentWorkspace, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Value="{x:Null}">
                    <Setter Property="dxb:BarButtonItem.IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>

it looks really stupid: like MS Word with documentless client area and at the same time with a lot of ready-for-click buttons in toolbar (with formatting and other document-specific features). Please, help me, 🙂

P.S. When adding to toolbar a button with DataContext binded to CurrentWorkspace, then its DataContextChanged event fires properly when activating or adding or removing workspace tab in the window. So, the problem somewhere in DataTrigger (or in View as generally), not in it’s ViewModel(s).

UPDATE

I uploaded sample project on VS2010, link for the archive: http://www.filefactory.com/file/b43455e/n/WhatIfCommandIsNull.rar

bellow its description.

  1. TextBox is bound to the ViewModel.Data property
  2. Assigning or removing ViewModel into/from Window.DataContext can be done by clicking two buttons – btAssignViewModel and btRemoveViewModel respectively
  3. ViewModel exposes two commands, one of which sets ViewModel.Data to string value, other – sets it to the NULL
  4. These commands are bound to the buttons btSetData & btResetData via their Button.Command properties

As you can see, when Window.DataContext is set to the ViewModel instance, both the commands working properly, & ResetDataCommand.CanExecute is working too (when ViewModel.Data is NULL, ResetDataCommand.CanExecute returns false & button btResetData is disabled). Once the Window.DataContext is set to null, last two buttons enables (for the first two ones trere are no commands are bound).

The problem is to realize declaratively (via triggers) next four rules:

  • If btAssignViewModel.DataContext is not null then btAssignViewModel.IsEnabled = false, else true.
  • If btRemoveViewModel.DataContext is null then btRemoveViewModel.IsEnabled = false, else true.
  • If ViewModel.Data is null then btSetData.IsEnabled = true, else false.
  • If ViewModel.Data is null then btResetData.IsEnabled = false, else true.

I think that first two rules can be realized using Triggers, second two – using DataTriggers. But they aren’t working, so I erased them from the project.

  • 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-05-17T23:52:12+00:00Added an answer on May 17, 2026 at 11:52 pm

    This might work (pending your circumstances)

    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Style.Triggers>
                <Trigger Property="Command" Value="{x:Null}">
                   <Setter Property="IsEnabled" Value="false"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short of copying the entire .netbeans directory is there any way to transfer custom
Short version: I want to trigger the Form_Load() event without making the form visible.
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific
Short of cutting and pasting, is there a way to sort the methods in
Short of putting a UIWebView as the back-most layer in my nib file, how
Short: how does modelbinding pass objects from view to controller? Long: First, based on
Short version: assuming I don't want to keep the data for long, how do
Short Version: When I've created a Channel using ChannelFactory on a client which uses
Short of inserting a try/catch block in each worker thread method, is there a
Short of rolling your own. There has to be something out there. FlexLM/FlexNet is

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.