Reputation: 43
I am working on a project using WPF where I have to display the computer's username as a text string in WPF.
I know we use %username% cmd command to retrieve the session username however how to use it in as a string in a WPF application?
Thank you
Upvotes: 1
Views: 247
Reputation: 130
First of all you need to install System.DirectoryServices.AccountManagement NuGet Package.
Then you have declare a string in your .cs file:
private string UsernameText = Environment.Username;
public string UsernameText
{
get => UsernameText;
set
{
if (UsernameText != value)
{
UsernameText = value;
}
}
}
and in your .xaml file:
<TextBlock Text="{Binding Path=SessionUsernameText, Mode=TwoWay}"/>
Upvotes: 1