首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过Expression Blend在blend中创建自定义按钮?

如何通过Expression Blend在blend中创建自定义按钮?
EN

Stack Overflow用户
提问于 2009-11-22 08:56:40
回答 2查看 2.5K关注 0票数 0

我已经在Expression Design中创建了一个图像,我正尝试将其导入Blend以创建一个按钮。当我在Blend中调整按钮的大小时,我试图让按钮与它的容器(最有可能是一个网格)一起缩放。不幸的是,这两种产品的文档都不是很有帮助。设计中的xaml如下所示:

代码语言:javascript
复制
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="Document" Width="61" Height="61" Clip="F1 M 0,0L 61,0L 61,61L 0,61L 0,0">
<Canvas x:Name="MinimizeButtonBase" Width="799.999" Height="600" Canvas.Left="0" Canvas.Top="0">
    <Viewbox x:Name="Group" Width="61" Height="61" Canvas.Left="0" Canvas.Top="0">
        <Canvas Width="61" Height="61">
            <Path x:Name="Path" Width="61" Height="61" Canvas.Left="0" Canvas.Top="3.05176e-005" Stretch="Fill" StrokeLineJoin="Round" Stroke="#B0000000" Data="F1 M 5.5,0.500031L 55.5,0.500031C 58.2614,0.500031 60.5,2.73859 60.5,5.5L 60.5,55.5C 60.5,58.2614 58.2614,60.5 55.5,60.5L 5.5,60.5C 2.73859,60.5 0.5,58.2614 0.5,55.5L 0.5,5.5C 0.5,2.73859 2.73859,0.500031 5.5,0.500031 Z ">
                <Path.Fill>
                    <LinearGradientBrush StartPoint="0.561118,0.955553" EndPoint="0.58334,-0.177781">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Color="#B0000000" Offset="0"/>
                            <GradientStop Color="#B0FFFFFF" Offset="1"/>
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Path.Fill>
            </Path>
            <Path x:Name="Line" Width="49.2547" Height="5" Canvas.Left="5.23578" Canvas.Top="47" Stretch="Fill" StrokeThickness="5" StrokeLineJoin="Round" Stroke="#B0000000" Data="M 7.73578,49.5L 51.9904,49.5"/>
        </Canvas>
    </Viewbox>
</Canvas>

有谁知道在设计中导入一个简单的2路径图像的步骤,使它成为blend中的一个按钮?当我将下面的xaml添加到blend中的资源文件中时,我无法让按钮在将其转换为控件后调整其大小时缩放到其容器。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-11-22 09:43:21

问题出现在你所使用的容器类型和它所产生的XAML的复杂性上,画布是绝对定位的,不应该真正用于缩放。为了解决这个问题,你可以使用一个视图框来模拟比例,但这并不是必需的。

我已经在表达式3中启动了一个项目,并添加了一个用户控件,将您的代码粘贴到其中,然后对其进行处理。下方水平路径相对于按钮底部的位置不清晰,如果您需要更改其位置和宽度,请适当更改网格列的高度和宽度值,并将它们保留为比率而不是绝对数。

代码语言:javascript
复制
<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Class="WpfApplication1.UserControl1"
    x:Name="UserControl">

    <Grid x:Name="Document">
         <Grid.ColumnDefinitions>
             <ColumnDefinition Width="1*"/>
             <ColumnDefinition Width="8*"/>
             <ColumnDefinition Width="1*"/>
         </Grid.ColumnDefinitions>
         <Grid.RowDefinitions>
             <RowDefinition Height="8*"/>
             <RowDefinition Height="1*"/>
             <RowDefinition Height="1*"/>
         </Grid.RowDefinitions>
         <Path Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="3"
               x:Name="Path" 
               Stretch="Fill" StrokeLineJoin="Round" Stroke="#B0000000" 
               Data="F1 M 5.5,0.500031L 55.5,0.500031C 58.2614,0.500031 60.5,2.73859 60.5,5.5L 60.5,55.5C 60.5,58.2614 58.2614,60.5 55.5,60.5L 5.5,60.5C 2.73859,60.5 0.5,58.2614 0.5,55.5L 0.5,5.5C 0.5,2.73859 2.73859,0.500031 5.5,0.500031 Z "> 
             <Path.Fill>                           
                 <LinearGradientBrush StartPoint="0.561118,0.955553" EndPoint="0.58334,-0.177781">         
                     <LinearGradientBrush.GradientStops> 
                         <GradientStop Color="#B0000000" Offset="0"/>                        
                         <GradientStop Color="#B0FFFFFF" Offset="1"/>     
                     </LinearGradientBrush.GradientStops> 
                 </LinearGradientBrush>                    
            </Path.Fill>                     
       </Path>     
       <Path x:Name="Line" Stretch="Fill"
             StrokeThickness="5" StrokeLineJoin="Round" Stroke="#B0000000" 
             Data="M 7.73578,49.5L 51.9904,49.5" 
             Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" />
    </Grid>
</UserControl>

如果它将成为一个适当的控件,那么你将不得不开始以这样或那样的形式添加内容呈现,但这应该解决了调整大小的问题。

编辑:我去掉了我设置的一些额外的对齐和页边距,因为它们不再是必要的。

票数 0
EN

Stack Overflow用户

发布于 2009-11-28 04:51:49

使事物可伸缩的最简单的布局容器是ViewBox。它是WPF中的一个标准控件,而在Silverlight中,它(我认为)在SL工具箱中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1777379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档