想添加樣式的按鈕,不明白爲什麼我要加入這一行的代碼,在這裏我不想任何邊框添加到我的按鈕:刪除空格填充緣周圍的ListViewItem
<Border Background="{TemplateBinding Background}">
的完整代碼:
<Style x:Key="ButtonStyleRed" TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<StackPanel Orientation="Horizontal" Width="200">
<Rectangle Width="4" Height="30" Fill="#64dd17" Margin="0,0,10,1" RadiusX="2" RadiusY="2"/>
<TextBlock Text="{Binding Path=DataContext.FlowStageName,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Button}}}"
VerticalAlignment="Center" FontSize="14" Foreground="White" TextWrapping="WrapWithOverflow"/>
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True"/>
<Trigger Property="IsDefaulted" Value="True"/>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#263238"></Setter>
</Trigger>
<Trigger Property="IsPressed" Value="True"/>
<Trigger Property="IsEnabled" Value="False"/>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="0"></Setter>
<Setter Property="Width" Value="200"/>
<Setter Property="Height" Value="50"/>
<Setter Property="Background" Value="#37474f"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
我會記住這這樣的,但還有許多事情不能太解決了其他一些填充或保證金的問題。
當我沒有這個邊界,setter屬性的背景顏色也不起作用。
編輯 當我將它改爲下面的時候,它使我留下了按鈕周圍的填充/邊距。 我已將Setters for Margin和Padding設置爲0,但這不起作用。
<StackPanel Orientation="Horizontal" Width="200" Background="{TemplateBinding Background}" Margin="{TemplateBinding Padding}">
<Rectangle Width="4" Height="30" Fill="#64dd17" Margin="0,0,10,1" RadiusX="2" RadiusY="2"/>
<TextBlock Text="{Binding Path=DataContext.FlowStageName,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Button}}}"
VerticalAlignment="Center" FontSize="14" Foreground="White" TextWrapping="WrapWithOverflow"/>
</StackPanel>
EDIT2
<views:BaseView.Resources>
<views:SwapBooleanValueConverter x:Key="SwapBooleanValueConverter" />
<DataTemplate x:Key="FlowStagesTemplate">
<StackPanel>
<Button x:Name="MenuStageButton"
Tag="{Binding ID}"
Command="{Binding DataContext.OnButtonClickCommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding ElementName=TurulStageButton}"
Style="{Binding FlowStageDisplayStyle}">
</Button>
<Rectangle VerticalAlignment="Stretch" Width="200" Margin="0" Height="1">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0" >
<GradientStop Color="#263238" Offset="0" />
<GradientStop Color="#78909c" Offset="0.5" />
<GradientStop Color="#263238" Offset="1.0" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</StackPanel>
</DataTemplate>
</views:BaseView.Resources>
<StackPanel Background="#263238">
<ListView ItemsSource="{Binding FlowStagesSubMenu}" ItemTemplate="{StaticResource FlowStagesTemplate}"
BorderThickness="0" Background="#263238" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</StackPanel>
該邊框沒有實際的「邊框」,僅用於顯示背景。沒有它,沒有任何元素可以完成這個任務,因此沒有背景。 – icebat
但我的按鈕看起來像裏面有填充,因爲背景不包括整個按鈕? – Whistler