I am assuming that you are instantiating and the second window from within the ViewModel that is bound to the button's Command property. This would typically be how this situation would be handled in MVVM. This allows you to create another property within your ViewModel that queries whether the window is open or not.
private Window _secondWindow = null; public bool SecondWindowIsOpen { get { return _secondWindow != null; } }
Then in your XAML you can bind the button's BackgroundColor to this property and use Triggers to determine the color.
<Window.Resources> <Style x:Key="WindowIsOpenButtonStyle" TargetType="{x:Type Button}"> <Style.Triggers> <DataTrigger Binding="{Binding SecondWindowIsOpen}" Value="True"> <Setter Property="Background" Value="Green" /> </DataTrigger> </Style.Triggers> </Style> </Window.Resources> <Grid> <Button Background="Yellow" Command="{Binding OpenSecondWindow}" Style="{StaticResource WindowIsOpenButtonStyle}" /> </Grid>
Now, when the window is open the button's background color will change to Yellow, and when it is closed again it will be revert back to it's original color.