List of Exercises

How to Add a Theme to Your WPF Project

	    

<Application x:Class="WPF_Theme.App"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="clr-namespace:WPF_Theme"

StartupUri="MainWindow.xaml">


<Application.Resources>

<Style TargetType="DataGridColumnHeader">

<Setter Property="HorizontalContentAlignment" Value="Center" />

<Setter Property="VerticalContentAlignment" Value="Center" />

<Setter Property="FontWeight" Value="Bold" />

<Setter Property="Padding" Value="10,5" />

</Style>

<Style TargetType="Button">

<Setter Property="Background" Value="#FF0078D7" />

<Setter Property="Foreground" Value="White" />

<Setter Property="FontSize" Value="14" />

<Setter Property="Padding" Value="10,5" />

<Setter Property="BorderThickness" Value="0" />

<Setter Property="BorderBrush" Value="Transparent" />

<Setter Property="HorizontalContentAlignment" Value="Center" />

<Setter Property="VerticalContentAlignment" Value="Center" />

<Setter Property="Cursor" Value="Hand" />

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="Button">

<Border Background="{TemplateBinding Background}"

CornerRadius="5"

Padding="{TemplateBinding Padding}">

<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"

VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />

</Border>

</ControlTemplate>

</Setter.Value>

</Setter>

<Setter Property="Effect">

<Setter.Value>

<DropShadowEffect BlurRadius="5" ShadowDepth="2" Color="#40000000" />

</Setter.Value>

</Setter>

<Style.Triggers>

<Trigger Property="IsMouseOver" Value="True">

<Setter Property="Background" Value="#FF005A9E" />

</Trigger>

<Trigger Property="IsEnabled" Value="False">

<Setter Property="Background" Value="#FFCCCCCC" />

<Setter Property="Foreground" Value="#FF666666" />

</Trigger>

</Style.Triggers>

</Style>


<Style TargetType="ProgressBar">

<Setter Property="Foreground" Value="#FF0078D7" />

<Setter Property="Background" Value="#FFCCCCCC" />

<Setter Property="BorderThickness" Value="0" />

<Setter Property="Height" Value="25" />

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="ProgressBar">

<Border Background="{TemplateBinding Background}"

CornerRadius="5">

<Grid x:Name="PART_Track">

<Rectangle x:Name="PART_Indicator"

Fill="{TemplateBinding Foreground}"

HorizontalAlignment="Left"

RadiusX="5" RadiusY="5" />

</Grid>

</Border>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</Application.Resources>

</Application>





<Window x:Class="WPF_Theme.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:WPF_Theme"

mc:Ignorable="d"

Title="MainWindow" Height="450" Width="800">

<Grid>

<Grid.RowDefinitions>

<RowDefinition Height="30"/>

<RowDefinition Height="Auto" />

<RowDefinition Height="*" />

</Grid.RowDefinitions>

<!-- Top Panel with Buttons and Progress Bar -->

<StackPanel Grid.Row="1" Margin="20">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">

<Button x:Name="select" Content="Select" Width="140" Margin="10,0" />

<Button x:Name="browseFolder" Content="Select Folder" Width="140" Margin="10,0" IsEnabled="False" />

<Button x:Name="Convert" Content="Convert Files" Width="140" Margin="10,0" IsEnabled="False" />

</StackPanel>


<!-- Progress Bar with Percentage -->

<Grid Margin="0,20">

<ProgressBar x:Name="progress" Value="{Binding ProgressValue}" />

<TextBlock Text="{Binding ProgressValue, StringFormat={}{0:F2}%}"

HorizontalAlignment="Center"

VerticalAlignment="Center"

Foreground="Black"

FontSize="14"

FontWeight="Bold" />

</Grid>

</StackPanel>


<!-- Report Section -->

<GroupBox Grid.Row="2" Header="Report" Margin="20,10" >

<DataGrid x:Name="dg" AutoGenerateColumns="False" ItemsSource="{Binding}" CanUserAddRows="False">

<DataGrid.Columns>

<!-- File Name Column -->

<DataGridTextColumn Header="File Name" Width="*" MinWidth="230" Binding="{Binding FileName}" />

<DataGridTextColumn Header="Number of Point" Width="*" MinWidth="150" Binding="{Binding NumPoint}" />

<DataGridTextColumn Header="MinMax/XY" Width="*" MinWidth="250" Binding="{Binding Domain}" />


</DataGrid.Columns>

</DataGrid>

</GroupBox>

</Grid>


</Window>




Download the project of Visual Studio 2022 in DropBox Download


Make Your WPF Project Look Amazing with Themes! C#


Video Thumbnail