拿一个按钮来说:
HTML/css
<div class="btn"><div>icon</div>按钮</div>
.btn {
color: red;
border: 1px solid #75a4ff;
padding: 10px;
border-radius: 15px;
height: 32px;
width: 76px
margin: 0 0 0 8px;
font-size: 10px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
&:hover {
color: #fff;
background: #75a4ff;
}
}
C# wpf:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:local="clr-namespace:WpfApp1.Components">
<Style TargetType="local:Button">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="#75a4ff"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Height" Value="32"/>
<Setter Property="Width" Value="76"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="Margin" Value="8,0,0,0"/>
<Setter Property="Foreground" Value="#75a4ff"/>
<Setter Property="FontSize" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:Button">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="15" Padding="2">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<mah:FontIcon FontFamily="Segoe MDL2 Assets" FontSize="10" Glyph="" HorizontalAlignment="Left">
<mah:FontIcon.Style>
<Style TargetType="mah:FontIcon">
<Setter Property="Foreground" Value="#75a4ff"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=local:Button}}" Value="True">
<Setter Property="Foreground" Value="White"/>
</DataTrigger>
</Style.Triggers>
</Style>
</mah:FontIcon.Style>
</mah:FontIcon>
<TextBlock Text="{Binding Content, RelativeSource={RelativeSource AncestorType=local:Button}}" Margin="8, 0, 0, 0">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="#75a4ff"/>
<Style.Triggers>
<DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=local:Button}}" Value="True">
<Setter Property="Foreground" Value="White"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#75a4ff"></Setter>
<Setter Property="Cursor" Value="Hand"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
写起来相当难受= =。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.