The form has a title for the Title window. I need to call the application for example: Test organization application, the word test is highlighted in bold.
Test organization application
How can this be done? I know if it was necessary to do something like this for the Label, then it’s not a problem, we add the Textblock in it and assign it to the Label. But in the title is not rolls. Can anyone come across?

  • Well, it's like a non-standard behavior, you need a non-standard window title ... - Andrew NOP
  • With non-standard behavior, I understand it. But how to make a custom window title? maybe you have an example? - Denis Ivanov

1 answer 1

The non-client area of ​​the window can be changed by applying a non-standard WindowChrome , for example, it might look something like this:

 <Window ...> <WindowChrome.WindowChrome> <!--Меняем WindowChrome--> <WindowChrome GlassFrameThickness="{x:Static WindowChrome.GlassFrameCompleteThickness}"/> </WindowChrome.WindowChrome> <Window.Template> <!--Меняем шаблон окна--> <ControlTemplate TargetType="c:MainWindow"> <Grid SnapsToDevicePixels="True"> <Grid.RowDefinitions> <!--Одна строка для заголовка--> <RowDefinition Height="Auto"/> <!--Одна для контента--> <RowDefinition/> </Grid.RowDefinitions> <!--Заголовок--> <StackPanel Orientation="Horizontal" Margin="7,7,7,0"> <!--Вернем иконку на место--> <Image Source="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" Width="16" Height="16" Margin="0,0,4,0"/> <!--Собственно текст заголовка, теперь его нужно редактировать здесь--> <TextBlock VerticalAlignment="Center"> Special for <Run FontWeight="Bold">stackoverflow</Run> </TextBlock> </StackPanel> <!--Контент будет вставляться сюда--> <Border Grid.Row="1" Margin="7" BorderBrush="Black" BorderThickness="1" Background="{TemplateBinding Background}"> <ContentPresenter Content="{TemplateBinding Content}"/> </Border> </Grid> </ControlTemplate> </Window.Template> <!--Ну а здесь уже идет обычный контент, который вы помещаете в окно--> <Grid Margin="5"> <TextBlock Text="Some text" VerticalAlignment="Center" HorizontalAlignment="Center"/> </Grid> </Window> 

enter image description here

The answer is prepared on the basis of this manual: https://blogs.msdn.microsoft.com/wpfsdk/2010/08/25/experiments-with-windowchrome/

WindowChrome since the .NET 4.5 part of PresentationFramework.dll, so no additional connection is required.


In order to return the system menu when clicking on the window icon, you need to turn it into a button (replace it in the Image markup with this fragment):

  <Button Margin="0,0,4,0" Click="ShowSystemMenu"> <Button.Template> <ControlTemplate TargetType="Button"> <ContentPresenter/> </ControlTemplate> </Button.Template> <Image Source="{Binding Icon, RelativeSource={RelativeSource TemplatedParent}}" Width="16" Height="16" WindowChrome.IsHitTestVisibleInChrome="True"/> </Button> 

and write in codebehind a click handler with the following content:

 private void ShowSystemMenu(object sender, RoutedEventArgs e) { var source = (FrameworkElement)e.OriginalSource; var locationFromScreen = source.PointToScreen(new Point(0, source.ActualHeight)); var presentationSource = PresentationSource.FromVisual(this); var targetPoint = presentationSource.CompositionTarget.TransformFromDevice.Transform(locationFromScreen); SystemCommands.ShowSystemMenu(this, targetPoint); } 

enter image description here

  • one
    But keep in mind that the display on different operating systems may differ significantly, it is necessary to test the behavior on different operating systems with different themes. However, this applies to the whole GUI :) - Andrew NOP