c# - WPF How to change header color of gridview -
i've been trying learn how customize listview contains gridview.
i've been able figure out , learn each part require... except one.
how change color of white lines between each header column name?
xaml:
<window x:class="uitest.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:uitest" mc:ignorable="d" title="mainwindow" height="200" width="400"> <stackpanel> <listview margin="0 50 0 0" name="lvusers" borderbrush="{x:null}" borderthickness="0" background="red" padding="0"> <listview.view> <gridview> <gridview.columnheadercontainerstyle> <style targettype="{x:type gridviewcolumnheader}"> <setter property="background" value="darkblue"></setter> <setter property="foreground" value="white"></setter> <setter property="borderbrush" value="{x:null}"></setter> <setter property="borderthickness" value="0"></setter> <setter property="margin" value="0"></setter> <setter property="padding" value="0"></setter> </style> </gridview.columnheadercontainerstyle> <gridviewcolumn header="name" width="120" displaymemberbinding="{binding name}" /> <gridviewcolumn header="age" width="50" displaymemberbinding="{binding age}" /> <gridviewcolumn header="mail" width="150" displaymemberbinding="{binding mail}" /> </gridview> </listview.view> <listview.itemcontainerstyle> <style targettype="listviewitem"> <setter property="background" value="blue"></setter> <setter property="foreground" value="white"></setter> </style> </listview.itemcontainerstyle> </listview> </stackpanel> </window>
and here .cs code:
using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using system.windows; using system.windows.controls; using system.windows.data; using system.windows.documents; using system.windows.input; using system.windows.media; using system.windows.media.imaging; using system.windows.navigation; using system.windows.shapes; namespace uitest { public partial class mainwindow : window { public mainwindow() { initializecomponent(); list<user> items = new list<user>(); items.add(new user() { name = "john doe", age = 42, mail = "john@doe-family.com" }); items.add(new user() { name = "jane doe", age = 39, mail = "jane@doe-family.com" }); items.add(new user() { name = "sammy doe", age = 7, mail = "sammy.doe@gmail.com" }); lvusers.itemssource = items; } public class user { public string name { get; set; } public int age { get; set; } public string mail { get; set; } } } }
this how done in application...
<style targettype="{x:type gridviewcolumnheader}"> <setter property="template"> <setter.value> <controltemplate targettype="{x:type gridviewcolumnheader}"> <border borderthickness="0,0,0,1" borderbrush="white" background="transparent"> <textblock x:name="contentheader" text="{templatebinding content}" padding="5,5,5,0" width="{templatebinding width}" textalignment="center" /> </border> </controltemplate> </setter.value> </setter> <setter property="overridesdefaultstyle" value="true" /> <setter property="foreground" value="white" /> </style>
see if helps.
Comments
Post a Comment