ProxiesPage.xaml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <Page x:Class="ClashDotNetFramework.Pages.ProxiesPage"
  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:ClashDotNetFramework.Pages"
  7. xmlns:converters="clr-namespace:ClashDotNetFramework.Models.Converters"
  8. xmlns:items="clr-namespace:ClashDotNetFramework.Models.Items"
  9. xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
  10. xmlns:wpftk="clr-namespace:WpfToolkit.Controls;assembly=VirtualizingWrapPanel"
  11. mc:Ignorable="d" FontSize="14" Loaded="Page_Loaded"
  12. d:DesignHeight="750" d:DesignWidth="780"
  13. Title="ProxiesPage">
  14. <Page.Resources>
  15. <converters:GroupNameToExpandedConverter x:Key="GroupNameToExpandedConverter"/>
  16. <converters:LatencyToColorConverter x:Key="LatencyToColorConverter"/>
  17. <converters:LatencyToTextConverter x:Key="LatencyToTextConverter"/>
  18. <converters:StatusToColorConverter x:Key="StatusToColorConverter"/>
  19. <Style x:Key="ButtonStyle" TargetType="ToggleButton">
  20. <Setter Property="BorderThickness" Value="0"/>
  21. <Setter Property="Foreground" Value="{DynamicResource ButtonUnCheckedForeground}"/>
  22. <Setter Property="Background" Value="{DynamicResource ButtonUnCheckedBackground}"/>
  23. <Setter Property="Cursor" Value="Hand"/>
  24. <Setter Property="Width" Value="120"/>
  25. <Setter Property="Height" Value="40"/>
  26. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  27. <Setter Property="VerticalContentAlignment" Value="Center"/>
  28. <Setter Property="Template">
  29. <Setter.Value>
  30. <ControlTemplate TargetType="ToggleButton">
  31. <Border CornerRadius="2" Background="{TemplateBinding Background}">
  32. <ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
  33. </Border>
  34. <ControlTemplate.Triggers>
  35. <Trigger Property="IsChecked" Value="True">
  36. <Setter Property="Foreground" Value="{DynamicResource ButtonCheckedForeground}"/>
  37. <Setter Property="Background" Value="{DynamicResource ButtonCheckedBackground}"/>
  38. <Setter Property="FontWeight" Value="SemiBold"/>
  39. </Trigger>
  40. </ControlTemplate.Triggers>
  41. </ControlTemplate>
  42. </Setter.Value>
  43. </Setter>
  44. </Style>
  45. <Style x:Key="TransparentButtonStyle" TargetType="Button">
  46. <Setter Property="BorderThickness" Value="0"/>
  47. <Setter Property="Background" Value="Transparent"/>
  48. <Setter Property="Cursor" Value="Hand"/>
  49. <Setter Property="Width" Value="70"/>
  50. <Setter Property="FontSize" Value="12"/>
  51. <Setter Property="HorizontalAlignment" Value="Center"/>
  52. <Setter Property="HorizontalContentAlignment" Value="Center"/>
  53. <Setter Property="VerticalAlignment" Value="Center"/>
  54. <Setter Property="VerticalContentAlignment" Value="Center"/>
  55. <Setter Property="Template">
  56. <Setter.Value>
  57. <ControlTemplate TargetType="Button">
  58. <Border CornerRadius="2" Background="{TemplateBinding Background}">
  59. <ContentPresenter x:Name="ContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalAlignment}"/>
  60. </Border>
  61. <ControlTemplate.Triggers>
  62. <Trigger Property="IsMouseOver" Value="True">
  63. <Setter Property="Background" Value="Transparent"/>
  64. </Trigger>
  65. </ControlTemplate.Triggers>
  66. </ControlTemplate>
  67. </Setter.Value>
  68. </Setter>
  69. </Style>
  70. <DataTemplate x:Key="ProxyItemTemplate" DataType="items:ProxyItem">
  71. <Border
  72. Background="{Binding IsSelected, Converter={StaticResource StatusToColorConverter}}"
  73. CornerRadius="2"
  74. Width="300">
  75. <Grid Margin="15,10,0,10">
  76. <Grid.ColumnDefinitions>
  77. <!-- Proxy Information -->
  78. <ColumnDefinition/>
  79. <!-- Check Latency Button -->
  80. <ColumnDefinition Width="70"/>
  81. </Grid.ColumnDefinitions>
  82. <!-- Proxy Information -->
  83. <Grid>
  84. <Grid.RowDefinitions>
  85. <!-- Proxy Name -->
  86. <RowDefinition/>
  87. <!-- Proxy Type -->
  88. <RowDefinition/>
  89. </Grid.RowDefinitions>
  90. <!-- Proxy Name -->
  91. <emoji:TextBlock
  92. Text="{Binding Name}"
  93. TextTrimming="CharacterEllipsis"
  94. Foreground="White"/>
  95. <!-- Proxy Type -->
  96. <emoji:TextBlock
  97. Grid.Row="1"
  98. Text="{Binding Type}"
  99. TextTrimming="CharacterEllipsis"
  100. Foreground="White"
  101. FontSize="12"
  102. Margin="0,5,0,0"/>
  103. </Grid>
  104. <!-- Check Latency Button -->
  105. <Button
  106. Grid.Column="1"
  107. Style="{StaticResource TransparentButtonStyle}"
  108. Tag="{Binding Name}"
  109. Foreground="{Binding Latency, Converter={StaticResource LatencyToColorConverter}}"
  110. Content="{Binding Latency, Converter={StaticResource LatencyToTextConverter}}"
  111. Click="TestButton_Click"/>
  112. </Grid>
  113. </Border>
  114. </DataTemplate>
  115. </Page.Resources>
  116. <Grid>
  117. <Grid.RowDefinitions>
  118. <!-- Top Buttons -->
  119. <RowDefinition Height="100"/>
  120. <!-- Proxy GridView -->
  121. <RowDefinition/>
  122. </Grid.RowDefinitions>
  123. <!-- Top Buttons -->
  124. <StackPanel
  125. Height="50"
  126. Orientation="Horizontal"
  127. HorizontalAlignment="Center"
  128. VerticalAlignment="Center">
  129. <!-- Direct Button -->
  130. <RadioButton
  131. GroupName="Mode"
  132. Style="{StaticResource ButtonStyle}"
  133. Content="Direct"
  134. Click="DirectButton_Click"
  135. x:Name="DirectButton"/>
  136. <!-- Rule Button -->
  137. <RadioButton
  138. IsChecked="True"
  139. GroupName="Mode"
  140. Style="{StaticResource ButtonStyle}"
  141. Margin="40,0,0,0"
  142. Content="Rule"
  143. Click="RuleButton_Click"
  144. x:Name="RuleButton"/>
  145. <!-- Global Button -->
  146. <RadioButton
  147. GroupName="Mode"
  148. Style="{StaticResource ButtonStyle}"
  149. Margin="40,0,0,0"
  150. Content="Global"
  151. Click="GlobalButton_Click"
  152. x:Name="GlobalButton"/>
  153. </StackPanel>
  154. <Separator
  155. VerticalAlignment="Bottom"
  156. Background="{DynamicResource SeparatorBackground}"/>
  157. <!-- Main Content -->
  158. <Grid
  159. Grid.Row="1"
  160. Margin="14,5,20,20">
  161. <ListView
  162. Background="Transparent"
  163. BorderBrush="Transparent"
  164. ScrollViewer.HorizontalScrollBarVisibility="Disabled"
  165. ItemTemplate="{StaticResource ProxyItemTemplate}"
  166. SelectionChanged="ProxyListView_SelectionChanged"
  167. SelectionMode="Single"
  168. VirtualizingPanel.CacheLengthUnit="Page"
  169. VirtualizingPanel.CacheLength="1,1"
  170. VirtualizingPanel.ScrollUnit="Pixel"
  171. VirtualizingPanel.VirtualizationMode="Standard"
  172. VirtualizingPanel.IsVirtualizingWhenGrouping="True"
  173. x:Name="ProxyListView">
  174. <ListView.ItemContainerStyle>
  175. <Style TargetType="ListViewItem">
  176. <Setter Property="Margin" Value="0,10,10,0"/>
  177. <Setter Property="Template">
  178. <Setter.Value>
  179. <ControlTemplate TargetType="ListViewItem">
  180. <ContentPresenter/>
  181. </ControlTemplate>
  182. </Setter.Value>
  183. </Setter>
  184. </Style>
  185. </ListView.ItemContainerStyle>
  186. <ListView.ItemsPanel>
  187. <ItemsPanelTemplate x:Name="ItemsPanelTemplate">
  188. <wpftk:VirtualizingWrapPanel
  189. SpacingMode="None"/>
  190. </ItemsPanelTemplate>
  191. </ListView.ItemsPanel>
  192. <ListView.GroupStyle>
  193. <GroupStyle HidesIfEmpty="True">
  194. <GroupStyle.ContainerStyle>
  195. <Style TargetType="{x:Type GroupItem}">
  196. <Setter Property="Template">
  197. <Setter.Value>
  198. <ControlTemplate>
  199. <Expander IsExpanded="{Binding Name, Mode=OneWay, Converter={StaticResource GroupNameToExpandedConverter}}">
  200. <Expander.Header>
  201. <emoji:TextBlock
  202. Text="{Binding Name}"
  203. Foreground="{DynamicResource NormalTextForeground}"
  204. FontSize="20"
  205. HorizontalAlignment="Left"
  206. Margin="10,0,0,0"/>
  207. </Expander.Header>
  208. <ItemsPresenter/>
  209. </Expander>
  210. </ControlTemplate>
  211. </Setter.Value>
  212. </Setter>
  213. </Style>
  214. </GroupStyle.ContainerStyle>
  215. <GroupStyle.Panel>
  216. <ItemsPanelTemplate>
  217. <VirtualizingStackPanel
  218. Orientation="{Binding Orientation, Mode=OneWay}" />
  219. </ItemsPanelTemplate>
  220. </GroupStyle.Panel>
  221. </GroupStyle>
  222. </ListView.GroupStyle>
  223. </ListView>
  224. </Grid>
  225. </Grid>
  226. </Page>