现在的位置: 首页 > 综合 > 正文

控件模板 1

2013年06月05日 ⁄ 综合 ⁄ 共 1191字 ⁄ 字号 评论关闭

简单的使用控件模板

<Button FontSize="15" HorizontalAlignment="Center" Content="Hello" Width="120" Height="30">
            <Button.Template>
                <ControlTemplate>
                    <Grid>
                        <Rectangle Fill="Red" RadiusX="15" RadiusY="15"/>
                        <TextBlock Name="textBlock" Margin="{TemplateBinding Button.Padding}" VerticalAlignment="Center"
                                    HorizontalAlignment="Center" Text="{TemplateBinding Button.Content}"/>
                    </Grid>
                </ControlTemplate>
            </Button.Template>
        </Button>

使用资源

<Window.Resources>
        <ControlTemplate x:Key="buttontemplate" TargetType="{x:Type Button}">
            <Border BorderBrush="Orange" BorderThickness="4" CornerRadius="3"
                    Background="Red" TextBlock.Foreground="Black" Margin="30">
                <ContentPresenter RecognizesAccessKey="True" HorizontalAlignment="Center"
                                   VerticalAlignment="Center"></ContentPresenter>
            </Border>
        </ControlTemplate>
    </Window.Resources>
    <StackPanel>
        <Button FontSize="15" Template="{StaticResource ResourceKey=buttontemplate}" Content="Hello">
        </Button>
    </StackPanel>

 

抱歉!评论已关闭.