代码之家  ›  专栏  ›  技术社区  ›  Matt Whitfield

WPF中的自定义形状边框[副本]

  •  3
  • Matt Whitfield  · 技术社区  · 15 年前

    我刚开始在WPF,所以可能我找错树了,但我想我需要得到一个边界,并附加到一个路径,以便我可以指定一些几何体的边界。。。但是,我找不到任何有用的信息。我在S/O上发现了一个“FreeFormContentControl”类,但它是用来将内容掩蔽到特定形状的,而不是在特定形状的内容周围绘制边框。

    1 回复  |  直到 15 年前
        1
  •  2
  •   Eugene Cheverda    15 年前

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

    它将左上角和右上角半径设置为2,左上角和右上角边界部分设置为2。

    更新:

    也可以创建自定义装饰器。提供更多信息 by this MSDN Article

    只需在TabItem控件模板中添加一些自大小的几何体。提供更多信息 this MSDN Article

    样品

    <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>