How can I change the font size of the header column of the datagrid? Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
I also find that I cannot change the font size of the contents of a listbox either. I need to do both in code...not xaml.
Thanks,
Paula
How can I change the font size of the header column of the datagrid? Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
I also find that I cannot change the font size of the contents of a listbox either. I need to do both in code...not xaml.
Thanks,
Paula
How can I change the font size of the header column of the datagrid?
The header of DataGrid
is DataGridColumnHeader
that under Microsoft.Toolkit.Uwp.UI.Controls.Primitives
name space. you could edit the default style like the following:
Edit in code behind
For example, if i want to modify the first column header's fontsize.
var colum = MyDataGrid.Columns[0] as DataGridBoundColumn;
var headerstyle = new Style(typeof(DataGridColumnHeader));
headerstyle.Setters.Add(new Setter(DataGridColumnHeader.FontSizeProperty, 12));
colum.HeaderStyle = headerstyle;
I also find that I cannot change the font size of the contents of a listbox either.
For ListBox content, we suggest you use binding that bind the FontSize with a value that comes from your data model or code behind.
For code behind
public int MyFontSize { get; set; }
public MainPage()
{
this.InitializeComponent();
this.DataContext = this;
MyFontSize = 25;
}
Xaml (and RootPage
is page name)
Thank you very much for the information! I got the data grid font working.
I'm still having an issue with the listbox though. I create it completely in c# - no xaml, so I'm not sure how to apply your suggestion above. I tried to create the data template in code and then set it to the listbox's datatemplate property but it's still not working.
Sorry, if I'm missing something simple and thanks again for the help.
I was able to solve my problem by creating the xaml in code and setting it to the listbox's itemtemplate:
Then for the listbox:
DataTemplate datatemplate = (DataTemplate)XamlReader.Load(GetDataTemplate().ToString());
ItemTemplate = datatemplate;
4 people are following this question.
How to write and read multiple types of data using Data Writer and Data Reader
Consuming UWP mail api from WPF Desktop Bridge App
Get Network usage information in UWP apps
How to Get/Set Cookies in Windows.Web.Http API
Switch the ListView Datatemplate from one data template to another data template?