There is a markup file for the button template:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyProj.UI.DesktopClient"> <!--Шаблон для кнопок--> <ControlTemplate x:Key="BlueButton" TargetType="{x:Type Button}"> <Border Name="Border" Background="#FF2F8FD1" BorderBrush="Black" CornerRadius="4" TextBlock.Foreground="White" TextBlock.FontWeight="Bold"> <Grid> <Rectangle Name="StrokeBorder" Stroke="Black" StrokeThickness="1" StrokeDashArray="1, 1"></Rectangle> <ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="Center" VerticalAlignment="Center"></ContentPresenter> </Grid> </Border> <ControlTemplate.Triggers> <!--При наведении мыши--> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Border" Property="Background" Value="#FF0044A6"></Setter> </Trigger> <!--При нажатии--> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="Border" Property="Background" Value="#FF003A63"></Setter> <Setter TargetName="Border" Property="TextBlock.Foreground" Value="Black"></Setter> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </ResourceDictionary> This file is declared in App.xaml:
<Application x:Class="MyProj.UI.DesktopClient.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyProj.UI.DesktopClient" StartupUri="Authorize.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <!--controltemplates--> <ResourceDictionary Source="Resources/ControlTemplates/ButtonTemplate.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application> In the window for the button I write the following code:
<Button Content="Войти в систему" Margin="5" Template="{DynamicResource BlueButton}"/> Everything compiles without problems, but this button is not really visible in the window. What could be the problem? Broke the whole head.
DynamicResource? StaticResource is enough, and the advantage of it is that if a template is not found, then it will tell you about it - ixSci