CustomControlPage.xaml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <Page x:Class="MvvmScaffoldFrame48.WPFPage.CustomControlPage"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  5. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6. xmlns:local="clr-namespace:MvvmScaffoldFrame48.WPFPage"
  7. mc:Ignorable="d"
  8. d:DesignHeight="450" d:DesignWidth="800"
  9. Title="CustomControlPage">
  10. <Grid>
  11. <Grid.ColumnDefinitions>
  12. <ColumnDefinition Width="*" />
  13. <ColumnDefinition Width="*" />
  14. </Grid.ColumnDefinitions>
  15. <Grid Grid.Column="0">
  16. <StackPanel Height="30" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center">
  17. <Label Content="红绿灯演示"></Label>
  18. <Ellipse Width="20" Height="20" Margin="48,0,0,0" >
  19. <Ellipse.Style>
  20. <Style TargetType="Ellipse">
  21. <Setter Property="Fill" Value="Red" />
  22. <Style.Triggers>
  23. <DataTrigger Binding="{Binding StaticTest}" Value="True">
  24. <Setter Property="Fill" Value="Green" />
  25. </DataTrigger>
  26. </Style.Triggers>
  27. </Style>
  28. </Ellipse.Style>
  29. </Ellipse>
  30. </StackPanel>
  31. <StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,40,0,0" Height="30">
  32. <Label Content="可以更改背景颜色的ComboBox:"/>
  33. <ComboBox Height="40" Width="140" ItemsSource="{Binding FormulationItems}" HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" FontSize="20">
  34. <ComboBox.Template>
  35. <ControlTemplate TargetType="ComboBox">
  36. <Grid>
  37. <ToggleButton
  38. Foreground="White"
  39. IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
  40. ClickMode="Press">
  41. <ToggleButton.Template>
  42. <ControlTemplate TargetType="ToggleButton">
  43. <Border x:Name="Border" Background="#FF0087FF" BorderBrush="#FFABADB3" BorderThickness="1">
  44. <Grid>
  45. <Grid.ColumnDefinitions>
  46. <ColumnDefinition />
  47. <ColumnDefinition Width="20" />
  48. </Grid.ColumnDefinitions>
  49. <ContentPresenter Grid.Column="0" Margin="3" />
  50. <Path x:Name="Arrow" Grid.Column="1"
  51. Fill="White"
  52. HorizontalAlignment="Center"
  53. VerticalAlignment="Center"
  54. Data="M 0 0 L 4 4 L 8 0 Z" />
  55. </Grid>
  56. </Border>
  57. <ControlTemplate.Triggers>
  58. <Trigger Property="IsMouseOver" Value="True">
  59. <Setter TargetName="Border" Property="Background" Value="LightBlue" />
  60. </Trigger>
  61. </ControlTemplate.Triggers>
  62. </ControlTemplate>
  63. </ToggleButton.Template>
  64. </ToggleButton>
  65. <ContentPresenter x:Name="ContentSite"
  66. IsHitTestVisible="False"
  67. Content="{TemplateBinding SelectionBoxItem}"
  68. ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
  69. Margin="3,3,23,3"
  70. VerticalAlignment="Center"
  71. HorizontalAlignment="Left"
  72. TextBlock.Foreground="White"/>
  73. <Popup x:Name="Popup"
  74. Placement="Bottom"
  75. IsOpen="{TemplateBinding IsDropDownOpen}"
  76. AllowsTransparency="True"
  77. Focusable="False"
  78. PopupAnimation="Slide">
  79. <Border x:Name="DropDownBorder"
  80. Background="#FF0087FF"
  81. BorderBrush="#FF0087FF"
  82. BorderThickness="1">
  83. <ScrollViewer Margin="0,3,0,3"
  84. SnapsToDevicePixels="True">
  85. <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
  86. </ScrollViewer>
  87. </Border>
  88. </Popup>
  89. </Grid>
  90. </ControlTemplate>
  91. </ComboBox.Template>
  92. <ComboBox.ItemContainerStyle>
  93. <Style TargetType="ComboBoxItem">
  94. <Setter Property="Background" Value="#FF0087FF" />
  95. <Setter Property="Foreground" Value="White" />
  96. <Style.Triggers>
  97. <Trigger Property="IsHighlighted" Value="True">
  98. <Setter Property="Background" Value="LightBlue" />
  99. </Trigger>
  100. </Style.Triggers>
  101. </Style>
  102. </ComboBox.ItemContainerStyle>
  103. </ComboBox>
  104. </StackPanel>
  105. <StackPanel Orientation ="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,80,0,0">
  106. <Label Content="圆角按钮:"/>
  107. <Button Content="圆角按钮" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" Background="#FF0123FF" FontWeight="Bold" FontSize="20" Foreground="White" Cursor="Hand" Command="{Binding TestCommand}">
  108. <Button.Template>
  109. <ControlTemplate TargetType="Button">
  110. <Border CornerRadius="5" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
  111. <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
  112. </Border>
  113. </ControlTemplate>
  114. </Button.Template>
  115. </Button>
  116. </StackPanel>
  117. <StackPanel Orientation ="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,120,0,0">
  118. <Label Content="悬浮提示框:"/>
  119. <Button Content="悬浮提示框" Name="PopupBtn" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" Click="PopupBtn_Click"/>
  120. <Popup Name="myPopup" Placement="Mouse" AllowsTransparency="True">
  121. <Border Background="LightYellow" BorderBrush="Gray" BorderThickness="1">
  122. <TextBlock Text="这是一个悬浮提示" Padding="10"/>
  123. </Border>
  124. </Popup>
  125. </StackPanel>
  126. <StackPanel Orientation ="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,160,0,0">
  127. <Label Content="悬浮窗口:"/>
  128. <Button Content="悬浮窗口" Name="FloatBtn" BorderThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" Click="FloatBtn_Click"/>
  129. </StackPanel>
  130. </Grid>
  131. </Grid>
  132. </Page>