MainWindow.xaml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <Window x:Class="WpfTest.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:WpfTest" xmlns:wpf="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
  7. mc:Ignorable="d"
  8. Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
  9. <Grid>
  10. <wpf:WebView2 x:Name="PdfWebView" Margin="112,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="600" Height="400" />
  11. <Grid Visibility="Collapsed" Width="300" Height="300" Margin="481,77,19,58"/>
  12. <ComboBox Name="testcombo" Height="60" Width="100" Loaded="testcombo_Loaded" Margin="8,196,692,179" >
  13. <ComboBox.ItemContainerStyle>
  14. <Style TargetType="ComboBoxItem">
  15. <Setter Property="Background" Value="#FF0087FF" />
  16. <Style.Triggers>
  17. <Trigger Property="IsHighlighted" Value="True">
  18. <Setter Property="Background" Value="#FF0087FF" />
  19. </Trigger>
  20. </Style.Triggers>
  21. </Style>
  22. </ComboBox.ItemContainerStyle>
  23. </ComboBox>
  24. <ComboBox Height="60" Width="100" Margin="6,29,0,0" HorizontalAlignment="Left" VerticalAlignment="Top">
  25. <ComboBox.Style>
  26. <Style TargetType="ComboBox">
  27. <!-- 设置ComboBox本身背景色 -->
  28. <Setter Property="Background" Value="Blue" />
  29. <Setter Property="Foreground" Value="White" />
  30. </Style>
  31. </ComboBox.Style>
  32. <!-- 设置下拉框部分的样式 -->
  33. <ComboBox.ItemContainerStyle>
  34. <Style TargetType="ComboBoxItem">
  35. <Setter Property="Background" Value="Blue" />
  36. <Setter Property="Foreground" Value="White" />
  37. <Style.Triggers>
  38. <Trigger Property="IsHighlighted" Value="True">
  39. <Setter Property="Background" Value="LightBlue" />
  40. </Trigger>
  41. </Style.Triggers>
  42. </Style>
  43. </ComboBox.ItemContainerStyle>
  44. <ComboBoxItem>1</ComboBoxItem>
  45. <ComboBoxItem>2</ComboBoxItem>
  46. </ComboBox>
  47. <ComboBox Height="60" Width="100" Margin="4,111,696,264">
  48. <ComboBox.Template>
  49. <ControlTemplate TargetType="ComboBox">
  50. <Grid>
  51. <ToggleButton x:Name="ToggleButton"
  52. Background="Blue"
  53. Foreground="White"
  54. IsChecked="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
  55. ClickMode="Press">
  56. <ToggleButton.Template>
  57. <ControlTemplate TargetType="ToggleButton">
  58. <Border x:Name="Border" Background="Blue" BorderBrush="DarkBlue" BorderThickness="1">
  59. <Grid>
  60. <Grid.ColumnDefinitions>
  61. <ColumnDefinition />
  62. <ColumnDefinition Width="20" />
  63. </Grid.ColumnDefinitions>
  64. <ContentPresenter Grid.Column="0" Margin="3" />
  65. <Path x:Name="Arrow" Grid.Column="1"
  66. Fill="White"
  67. HorizontalAlignment="Center"
  68. VerticalAlignment="Center"
  69. Data="M 0 0 L 4 4 L 8 0 Z" />
  70. </Grid>
  71. </Border>
  72. <ControlTemplate.Triggers>
  73. <Trigger Property="IsMouseOver" Value="True">
  74. <Setter TargetName="Border" Property="Background" Value="LightBlue" />
  75. </Trigger>
  76. </ControlTemplate.Triggers>
  77. </ControlTemplate>
  78. </ToggleButton.Template>
  79. </ToggleButton>
  80. <ContentPresenter x:Name="ContentSite"
  81. IsHitTestVisible="False"
  82. Content="{TemplateBinding SelectionBoxItem}"
  83. ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
  84. Margin="3,3,23,3"
  85. VerticalAlignment="Center"
  86. HorizontalAlignment="Left"
  87. TextBlock.Foreground="White"/>
  88. <Popup x:Name="Popup"
  89. Placement="Bottom"
  90. IsOpen="{TemplateBinding IsDropDownOpen}"
  91. AllowsTransparency="True"
  92. Focusable="False"
  93. PopupAnimation="Slide">
  94. <Border x:Name="DropDownBorder"
  95. Background="Blue"
  96. BorderBrush="DarkBlue"
  97. BorderThickness="1">
  98. <ScrollViewer Margin="0,3,0,3"
  99. SnapsToDevicePixels="True">
  100. <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" />
  101. </ScrollViewer>
  102. </Border>
  103. </Popup>
  104. </Grid>
  105. </ControlTemplate>
  106. </ComboBox.Template>
  107. <ComboBox.ItemContainerStyle>
  108. <Style TargetType="ComboBoxItem">
  109. <Setter Property="Background" Value="Blue" />
  110. <Setter Property="Foreground" Value="White" />
  111. <Style.Triggers>
  112. <Trigger Property="IsHighlighted" Value="True">
  113. <Setter Property="Background" Value="LightBlue" />
  114. </Trigger>
  115. </Style.Triggers>
  116. </Style>
  117. </ComboBox.ItemContainerStyle>
  118. </ComboBox>
  119. <Button Content="Button" Height="40" Margin="20,280,0,0" Width="75" VerticalAlignment="Top" HorizontalAlignment="Left" Click="Button_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. </Grid>
  126. </Window>