Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

WPF: Change background at runtime
 
How do I change the background color of a WPF element at runtime?
 
Solution:
You can fill the background of a WPF element with a brush
To do this you have to fill the FrameworkElement.Background with a new SolidColorBrush.
 
A SolidColorBrush can be created directly from the colors red green and blue using Color.FromArgb (..)

btnMoveTo_Subfolders.Background = new SolidColorBrush(Color.FromArgb( a:255, r:0, 255, 0));

 
 
In the view:
The background color of the button was set to Red = 255.
Alpha = 255 means full colors, alpha = 0 means full transparency

 
Parameters for Color.FromArgb
1.Parameter Alpha is equivalent to the opposite transparency
0 = transparent 255 = full color
// * Parameters Color.FromArgb (Alpa: 150, Red: 0, Green: 255, Blue: 0)
// * alpha 0 = transparent 255 = fullcolor

 
 
Code example in C # for adjusting the background color of a button control

public void check_BtnMove_on_Titels_filled()
{
//----------------< check_UcFolders_Titels_filled() >----------------
//*Parameters Color.FromArgb(Alpa:150, Red:0, Green:255, Blue:0)
//*Alpha 0=transparent 255=full color
 
if (check_UcFolders_Titels_filled()==true )
{
//to green
btnMoveTo_Subfolders.Background = new SolidColorBrush(Color.FromArgb( 150, 0, 255, 0));
}
else
{
//to red
btnMoveTo_Subfolders.Background = new SolidColorBrush(Color.FromArgb(150, 255, 0, 0));
}

//----------------</ check_UcFolders_Titels_filled() >----------------
}

 
Mobile
»
WPF Datagrid: Set Color of Row when it has no Focus
»
WPF Datagrid: Change the Color of Selected Row
»
WPF: Change Selected Row Color in DataGrid
»
WPF: Read SelectedItem from DataGrid with Dynamic As Anonymous Type
»
WPF: Elements too wide, edge Cut off
»
Solved: System.InvalidCastException HResult 0x80004002 in Select DataGrid
»
WPF: Combobox Selected Value
»
WPF Datagrid: Column is not displayed
»
WPF: Show video in preview
»
WPF Webbrowser: Suppress Java Errors or Set WebBrowser to Silent

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de