CustomControlPage.xaml 11 KB

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