Custom frame in WPF

I am trying to create a TabControl that matches the style of an existing tab control that I use in WinForms, and one of the features of this is that it has tab button shapes similar to those in VS (left tilt, other edges) .

I'm just starting to work in WPF, so maybe I'm sneaking up on the wrong tree, but I decided that I need to get the Border and bind it to the Path so that I can specify some geometry for the border. However, I cannot find any useful information. I found the FreeFormContentControl class in S / O, but this is intended to mask the contents of a specific form, and not to draw a border around it in a specific form.

If someone can point me in the right direction, I would be very obliged!

+3
source share
1 answer

You can specify the BorderThickness and CornerRadius border properties in terms of an individual value for each side, for example:

<Border CornerRadius="2,2,0,0" BorderThickness="2,2,2,0"/>

It will have a radius of topLeft and topRight angles set to 2, and the left, top and right boundary parts set to 2.

UPDATE:

You can also create your own Adorner. Additional information provided by this MSDN article

And just add some custom size geometry to your TabItem control template. For more information about him provided this MSDN article

SAMPLE

<Style TargetType="{x:Type TabItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type TabItem}">
                        <Grid>
                            <Viewbox Width="{TemplateBinding Width}"  Height="{TemplateBinding Height}" Stretch="Fill" StretchDirection="DownOnly">
                                <Path x:Name="path" Stretch="Fill" Stroke="Black" Fill="{StaticResource LightBrush}" Width="Auto" Height="Auto" Data="M 0,20 L 0,5 5,0 100,0 100,20 "/>
                            </Viewbox>

                            <Border Visibility="Visible"
            x:Name="Border"                                                                  
            Margin="5,1,0,1" >
                                <ContentPresenter x:Name="ContentSite"
              VerticalAlignment="Center"
              HorizontalAlignment="Center"
              ContentSource="Header"
              Margin="12,2,12,2"
              RecognizesAccessKey="True"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Panel.ZIndex" Value="100" />
                                <Setter TargetName="path" Property="Fill" Value="{StaticResource WindowBackgroundBrush}" />

                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="path" Property="Fill" Value="{StaticResource DisabledBackgroundBrush}" />
                                <Setter TargetName="path" Property="Stroke" Value="{StaticResource DisabledBorderBrush}" />
                                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
+2

Source: https://habr.com/ru/post/1755316/


All Articles