6
A
回答
4
您必須修改控件模板或樣式以更改現有控件的外觀。看看這個樣本,它與你的要求有些相似。我所做的是我改變了Chrome(默認風格的Windows),並創建了我自己的邊框和內容主持人的風格。然後我創建了風格的觸發器。爲了可視化,在鼠標懸停和缺血事件中,我正在改變邊框的背景顏色。
<Window.Resources>
<Style x:Key="ToggleButtonStyle1" TargetType="{x:Type ToggleButton}">
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="border">
<ContentPresenter
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
RecognizesAccessKey="True" TextElement.Foreground="White" HorizontalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsKeyboardFocused" Value="true"/>
<Trigger Property="IsChecked" Value="true">
<Setter Property="Background" TargetName="border" Value="#FF6C6C6C"/>
<Setter Property="CornerRadius" TargetName="border" Value="5"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="border" Value="#FF282828"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="#ADADAD"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<ToggleButton HorizontalAlignment="Left" Margin="136,59,0,0" Style="{DynamicResource ToggleButtonStyle1}" VerticalAlignment="Top" Width="27" Height="24" Content="-" FontSize="21.333" FontWeight="Bold" HorizontalContentAlignment="Center" Padding="0" VerticalContentAlignment="Center" IsThreeState="True"/>
</Grid>
4
是的,你想用ControlTemplate
來改變ToggleButton
的外觀。看看爲ToggleButton
的頁面,以及這篇文章:
Customizing the Appearance of an Existing Control by Creating a ControlTemplate
,讓你開始。
相關問題
- 1. Xamarin.Android中的自定義ToggleButton
- 2. 自定義ToggleButton setChecked(..)問題
- 3. android自定義togglebutton邊框
- 4. WPF自定義DependencyProperty通知更改
- 5. 當按下togglebutton時Wpf ToggleButton更改邊框背景
- 6. WPF ToggleButton不正確的渲染行爲
- 7. WPF togglebutton如何切換2個自定義畫筆
- 8. WPF togglebutton
- 9. 基於自定義ToggleButton的Radiobutton樣式
- 10. ToggleButton - >更改TextView
- 11. 更改自定義CursorAdapter的行佈局
- 12. 更改WPF中自定義複選框的圖像
- 13. ToggleButton UserControl中的WPF模板綁定
- 14. WPF ToggleButton IsChecked綁定問題
- 15. 自定義控件中的WPF自定義IList DependencyProperty行爲奇怪
- 16. C#WPF ToggleButton在觸發器中更改多個屬性?
- 17. Wpf Listbox和Togglebutton
- 18. jqgrid - 更改爲自定義排序icos
- 19. Xamarin.iOS更改bordercolor爲自定義控件
- 20. 點擊WPF ToggleButton更改其他ToggleButtons的值
- 21. XAML更改Togglebutton中的圖像源
- 22. 更改自定義WPF組合框的背景
- 23. gerrit中的自定義更改ID
- 24. 更改uitableviewcell中的自定義accessoryView?
- 25. 如何從ViewModel更改ToggleButton?
- 26. wpf databound自定義控件 - 爲什麼對自定義控件未檢測到數據源的更改?
- 27. 在WPF中,將綁定行的顏色更改爲DataGrid
- 28. 綁定到WPF ToggleButton的IsChecked狀態
- 29. 更改自定義UITableViewCell
- 30. WPF:使用自定義行爲綁定到類的屬性