background - How to set the SystemColors.HighlightBrushKey in WPF with a Converter -


I'm trying to set up SystemColors. Highlightbrush is always a bit darker than the background of the selected row. Therefore use this code im:

App.xaml:

  & lt; WPFTests2: SelectionBackgroundConverter X: main = "SelectionBackgroundConverter" /> & Lt; SolidColorBrush X: Main = "{x: Static SystemColors.HighlightBrushKey}" color = "{binding background, converter = {StaticResource SelectionBackgroundConverter}}" /> & Lt; /Application.Resources>  

Window 1 XML:

  & lt; Window x: orbit = "WPFTests2.Window1" xmlns = "http: /ssites.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" window1 "height =" 300 "width =" 300 "loaded =" window_loaded "& gt; & Lt; Grid & gt; & Lt; List Box X: Name = "LB" Horizontal Alignment = "Statch" Vertical Element = "Statch" /> & Lt; / Grid & gt;  

Window 1.xaml.cs:

  Using the system; Using System.Globalization; Using System.Windows; Using System.Windows.Data; System.Windows.Media; Namespace WPFTests2 {/// & lt; Summary & gt; /// Window 1. Interaction logic for xaml /// & lt; / Summary & gt; Public Partial Segment Window 1: Window {Public Window 1 () {Initial Group (); } Private Zero Window_loaded (Object Sender, Routing Avenger, ARGs E) {lb.imes.ed ("text1"); LB.Items.Add ("Lesson 2"); LB.Items.Add ("Lesson 3"); LB.Items.Add ("text4"); LB.Items.Add ("Text5"); }} Public Selection SelectionBackgroundConverter: IValueConverter {Public Object Convert (Object Value, Type TargetType, Object Parameter, CultureInfo Culture) {if (! Value = Faucet} {SolidColorBrush Brush = (SolidColorBrush) value; Color newCol = brush.Color; NewCol.R - = 10; NewCol.G - = 10; NewCol.B - = 10; Brush Canon Conif = New Bronze Connor (); Brush Nibush = (brush) conv.ConvertTo (newCol, typeof (brush)); Return a new brush; } Return Brush. Family; } Public Object Convertback (Object Value, Type Type, Object Parameter, Culture Info Culture) {// Never Call Back Return; }}}  

The problem is that the converter never calls ... does anyone know that before selecting it to set a bit darker background for?

Update

It looks like its work but unfortunately not completely. When I make the converter correct for viewing this way:

  Public Selection SelectionBackgroundConverter: IValueConverter {Public Object Convert (Object Value, Type TargetType, Object Parameter, CultureInfo Culture) {If (value = Null ) {SolidColorBrush brush = (SolidColorBrush) value; Color newCol = brush.Color; NewCol.R - = 10; NewCol.G - = 10; NewCol.B - = 10; Revert New SolidColorBrush (newCol); } Return Brush. Family; } Public Object Convertback (Type Object Value, Type Type, Object Parameter, Culture Enough Culture) {// We intend to never call it a return tap; }  

The problem now is that the converter becomes a call only once, I mean if I start the program and any row is clicked on the converter, If I click on another line, datagrid or control converter, then it is not called.

How can I correct any ideas?

  color = "{binding background, converter = {static resource selection backgrach converter}} " 

There is no source , and the background property will not be present in the current context. Change this to:

  color = "{binding source = {x: static SystemColors.HighlightBrush}, converter = {StaticResource SelectionBackgroundConverter}}"  

and your converter called Go Although your converter has bugs, but you should start it.

  • Caching the brush (if you do a lot in your app)
  • / html>

    Comments

    Popular posts from this blog

    c++ - Linux and clipboard -

    What is expire header and how to achive them in ASP.NET and PHP? -

    sql server - How can I determine which of my SQL 2005 statistics are unused? -