Hello,
Welcome to our Microsoft Q&A platform!
You can assign the variable to ListView.Header
:
xaml
<ListView.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" Foreground="Red"/>
</DataTemplate>
</ListView.HeaderTemplate>
xaml.cs
TestListView.Header = "Test";
If you need to set the header using bindings, in order to change the UI when you change the variable, you need to implement the INotifyPropertyChanged
interface:
public sealed partial class MainPage : Page, INotifyPropertyChanged
{
private string _testHeader;
public string TestHeader
{
get => _testHeader;
set
{
_testHeader = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
// ....
}
Usage
<ListView x:Name="TestListView" Header="{x:Bind TestHeader,Mode=OneWay}" ... >
...
</ListView>
Thanks.