title: WPF button command binding refreshed, but button still disabled
body: <p>I have a weird problem with a button's Command binding not being updated...</p>
  
  <p>I have an app written with MvvmLight, that allows users to maintain a list of medical systems. These systems are built from templates (ie a template might specify two cameras, one framegrabber and so on, as well as details about what each of these parts should contain). If the template is modified, the systems can be upgraded to use the new template. Both the system window and the templates window are modeless, so the templates can be modified while a system is being viewed. The templates window view model sends out a message if the template is updated, so that any open system windows can react accordingly.</p>
  
  <p>The system view holds a Border that is used to warn the user when they need to upgrade the system. The Visibility of the Border is bound to a bool property on the system entity that compares the system's revision number with the latest revision number of the underlying template. If they are on the latest template revision, the Visibility is set to Collapsed, so they don't see the contents.</p>
  
  <p>If the system uses an older revision, the Border is visible, and the content contains a message informing them of the need to upgrade, as well as button that does the upgrade. I have three scenarios with this border and button...</p>
  
  <p>1) If the system uses an out-of-date revision when the window is opened, the border is shown, and the button is visible. If the template is modified, the message updates correctly to show the new number, and the button remains visible. This is correct.</p>
  
  <p>2) If the system was using the latest template revision when it was opened, then when the template is revised, the border is displayed correctly, the message is updated correctly, and the button is enabled. Again, this is correct, as long as I close the system window afterwards.</p>
  
  <p>3) However, if I click the update button, then after the system is upgraded and the border is hidden, I update the template again, then when the border is redisplayed, the button is disabled. I tried removing all the logic from the CanExecute method and just returning true, so the button should be enabled, but it isn't. I have to close the system window and reopen it to enable the button.</p>
  
  <p>I tried adding an event to the view model, which I raised whenever the template was updated. I caught this event in the view and manually refreshed the button's command binding. However, this did NOT cause the CanExecute method to be called again, and the button remained disabled.</p>
  
  <p>I realise that this is all a bit confusing, and hard to debug without seeing the whole thing, but I'm hoping someone might be able to give me some clues. In case it helps, here is the relevant code...</p>
  
  <p>First, the XAML for the border, message and button...</p>
  
  <pre><code>&lt;Border Visibility="{Binding Converter={StaticResource BoolToVisibilityVC}, Path=NotUsingLatestDhrTemplate, ConverterParameter=true}"
          HorizontalAlignment="Stretch"
          Margin="3"
          Grid.Row="3"
          BorderBrush="Red"
          BorderThickness="2"
          Background="#FFFFEBEB"&gt;
    &lt;Grid Margin="3"
          gridHelper:GridHelper.GridRows="*,Auto"&gt;
      &lt;WrapPanel&gt;
        &lt;TextBlock Text="This PCR uses template revision "
                    VerticalAlignment="Center" /&gt;
        &lt;TextBlock Text="{Binding TemplateRevisionForThisDhr}"
                    VerticalAlignment="Center" /&gt;
        &lt;TextBlock Text=", but the current template revision is "
                    VerticalAlignment="Center" /&gt;
        &lt;TextBlock Text="{Binding LatestTemplateRevisionForThisPartDefinitionType}"
                    VerticalAlignment="Center" /&gt;
        &lt;telerik:RadButton Name="UpdateDhrButton"
                            Click="UpdateDhrButton_OnClick"
                            Command="{Binding Path=DataContext.UpdateDhrCommand, ElementName=DhrViewX}"
                            Margin="0,0,10,0"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Stretch"
                            IsEnabledChanged="UpdateDhrButton_IsEnabledChanged"&gt;
          &lt;StackPanel Orientation="Horizontal"
                      Margin="1"&gt;
            &lt;Image Margin="0,0,3,0"
                    Width="16"
                    Height="16"
                    Source="/Images;component/Images/battery.png" /&gt;
            &lt;TextBlock&gt;Update PCR&lt;/TextBlock&gt;
          &lt;/StackPanel&gt;
        &lt;/telerik:RadButton&gt;
      &lt;/WrapPanel&gt;
    &lt;/Grid&gt;
  &lt;/Border&gt;
  </code></pre>
  
  <p>There isn't any point in showing the CanExecute method, as all it contains is "return true;" at the moment!</p>
  
  <p>It looks as if there is some odd interaction going on between the visibility of the border and the enabled state of the button, and this seems to be overriding the CanExecute method's result.</p>
  
  <p>Anyone any ideas? Please feel free to ask if I forgot to add anything important here. Thanks in advance.</p>