Home > Net >  Segoe MDL2 Assets Regular font on one button
Segoe MDL2 Assets Regular font on one button

Time:09-27

Is there a way to add Segoe MDL2 Assets with regular text in the same button in WPF Xaml. Working on a side menu that I want to have icons text buttons.

CodePudding user response:

You can directly set the Button.Content property:

<Window>
  <Window.Resources>
    <Viewbox x:Key="ErrorIcon"
             x:Shared="False">
      <TextBlock Foreground="{Binding RelativeSource={RelativeSource AncestorType=Control}, Path=Foreground}"
                 FontFamily="Segoe MDL2 Assets"
                 FontSize="11"
                 Text="&#xE783;" />
    </Viewbox>
  </Window.Resources>

  <Button>
    <StackPanel Orientation="Horizontal">
      <ContentControl Content="{Staticresource ErroIcon}"
                      Foreground="Red" />
      <TextBlock Text="Some button text" />
    </StackPanel>
  </Botton>
</Window>

You can override the ControlTemplate of the Button or extend Button if you want to implement it with reusability in mind.

  •  Tags:  
  • wpf
  • Related