M
mrsopel
Guest
mrsopel Asks: WPF STYLES - button with connected boolean variable changing background collor
I would like to achive such configuration: button style in my WPF app - I have a process/windows service with hundreds of BOOL variables which I need to change a state from my WPF app/UI. Those variables can be controlled also by other apps.
So I have created a model/class in my WPFapp which is quering those variables and updating my internal variables states based on data. This is working fine.
I have such WORKING objects in my WPF View (for test)
And this in my VM:
How to change this to the style? I would like to have a button style and in my View call this style and just connect a variable from my ViewModel (each button will have different variable connected - this button style will be used in multiple View with mutliple variables from ViewModel)
I would like to achive such configuration: button style in my WPF app - I have a process/windows service with hundreds of BOOL variables which I need to change a state from my WPF app/UI. Those variables can be controlled also by other apps.
So I have created a model/class in my WPFapp which is quering those variables and updating my internal variables states based on data. This is working fine.
I have such WORKING objects in my WPF View (for test)
Code:
<Button Width="30" Height="30">
<Button.Resources>
<Style TargetType="Button">
<Setter Property="Background"
Value="Gray" />
<Style.Triggers>
<DataTrigger Binding="{Binding LifeBitVariable}" Value="True">
<Setter Property="Background" Value="Green" />
</DataTrigger>
<DataTrigger Binding="{Binding LifeBitVariable}" Value="False">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Resources>
</Button>
And this in my VM:
Code:
public bool LifeBitVariable
{
get { return communication.LifeBitVariable; }
set { communication.LifeBitVariable = value; NotifyPropertyChanged(); }
}
How to change this to the style? I would like to have a button style and in my View call this style and just connect a variable from my ViewModel (each button will have different variable connected - this button style will be used in multiple View with mutliple variables from ViewModel)