MainWindow.xaml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <Window x:Class="XamlTestApplication.MainWindow"
  2. xmlns="https://github.com/avaloniaui"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:local="clr-namespace:XamlTestApplication;assembly=XamlTestApplicationPcl"
  5. xmlns:vm="clr-namespace:XamlTestApplication.ViewModels;assembly=XamlTestApplicationPcl"
  6. Title="Avalonia Test Application" Width="800" Height="600">
  7. <Grid RowDefinitions="Auto,*,Auto" ColumnDefinitions="*,*">
  8. <Menu Grid.ColumnSpan="2">
  9. <MenuItem Header="_File">
  10. <MenuItem Header="_Open" Command="{Binding OpenFileCommand}" />
  11. <MenuItem Header="_Open Folder" Command="{Binding OpenFolderCommand}" />
  12. <MenuItem Header="_Hello">
  13. <MenuItem Header="_Goodbye"/>
  14. <Separator/>
  15. <MenuItem Header="_World" />
  16. </MenuItem>
  17. <Separator Background="Red"/>
  18. <MenuItem Header="_Test"/>
  19. <Separator/>
  20. <MenuItem Name="exitMenu" Header="_Exit"/>
  21. </MenuItem>
  22. </Menu>
  23. <TabControl Grid.Row="1" Grid.ColumnSpan="2" Padding="5">
  24. <TabControl.Transition>
  25. <PageSlide Duration="0.25" />
  26. </TabControl.Transition>
  27. <TabItem Header="Buttons">
  28. <ScrollViewer CanScrollHorizontally="False">
  29. <StackPanel Margin="10" Gap="4">
  30. <TextBlock Text="Button" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  31. <TextBlock Text="A button control" FontSize="13" Foreground="#727272" Margin="0,0,0,10" />
  32. <Button Content="Button" Width="150" />
  33. <Button Content="Button" Width="150" IsEnabled="False" />
  34. <TextBlock Text="ToggleButton" Margin="0, 40, 0, 0" FontSize="20" Foreground="#212121" />
  35. <TextBlock Text="A toggle button control" FontSize="13" Foreground="#727272" Margin="0,0,0,10" />
  36. <ToggleButton Width="150" IsChecked="True" Content="On" />
  37. <ToggleButton Width="150" IsChecked="False" Content="Off" />
  38. </StackPanel>
  39. </ScrollViewer>
  40. </TabItem>
  41. <TabItem Header="Text">
  42. <StackPanel Margin="10" Gap="4">
  43. <TextBlock Text="TextBlock with ContextMenu" FontWeight="Medium" FontSize="20" Foreground="#212121">
  44. <TextBlock.ContextMenu>
  45. <ContextMenu>
  46. <MenuItem Header="Testing 1" />
  47. <MenuItem Header="Testing 2" />
  48. <MenuItem Header="Testing 3" />
  49. <MenuItem Header="Testing 4">
  50. <MenuItem Header="SubItem 1" />
  51. <MenuItem Header="SubItem 2" />
  52. <MenuItem Header="SubItem 3" />
  53. <MenuItem Header="SubItem 4" />
  54. </MenuItem>
  55. </ContextMenu>
  56. </TextBlock.ContextMenu>
  57. </TextBlock>
  58. <TextBlock Text="A control for displaying text."
  59. FontSize="13"
  60. Foreground="#727272"
  61. Margin="0, 0, 0, 10" />
  62. <TextBlock Text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." FontSize="11" />
  63. <TextBlock Text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." FontSize="11"
  64. FontWeight="Medium" />
  65. <TextBlock Text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." FontSize="11"
  66. FontWeight="Bold" />
  67. <TextBlock Text="Lorem ipsum dolor sit amet, consectetuer adipiscing elit." FontSize="11"
  68. FontStyle="Italic" />
  69. <TextBlock Margin="0,40,0,0" Text="HtmlLabel" FontWeight="Medium" FontSize="20"
  70. Foreground="#212121" />
  71. <TextBlock Text="A label capable of displaying HTML content" FontSize="13" Foreground="#727272"
  72. Margin="0, 0, 0, 10" />
  73. </StackPanel>
  74. </TabItem>
  75. <TabItem Header="Input">
  76. <ScrollViewer CanScrollHorizontally="False">
  77. <StackPanel Margin="10" Gap="4">
  78. <TextBlock Text="TextBlock" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  79. <TextBlock Text="A text box control"
  80. FontSize="13"
  81. Foreground="#727272"
  82. Margin="0, 0, 0, 10" />
  83. <TextBox Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit." Width="200" />
  84. <TextBox Width="200" Watermark="Watermark" />
  85. <TextBox Width="200" Watermark="Floating Watermark" UseFloatingWatermark="True" />
  86. <TextBox AcceptsReturn="True" TextWrapping="Wrap" Width="200" Height="150"
  87. Text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." />
  88. <TextBox Width="200" Text="Left aligned text" TextAlignment="Left" />
  89. <TextBox Width="200" Text="Center aligned text" TextAlignment="Center" />
  90. <TextBox Width="200" Text="Right aligned text" TextAlignment="Right" />
  91. <TextBlock Margin="0, 40, 0, 0" Text="CheckBox" FontWeight="Medium" FontSize="20"
  92. Foreground="#212121" />
  93. <TextBlock Text="A check box control" FontSize="13" Foreground="#727272" Margin="0, 0, 0, 10" />
  94. <CheckBox IsChecked="True" Margin="0, 0, 0, 5" Content="Checked" />
  95. <CheckBox IsChecked="False" Content="Unchecked" />
  96. <TextBlock Margin="0, 40, 0, 0" Text="RadioButton" FontWeight="Medium" FontSize="20"
  97. Foreground="#212121" />
  98. <TextBlock Text="A radio button control" FontSize="13" Foreground="#727272"
  99. Margin="0, 0, 0, 10" />
  100. <RadioButton IsChecked="True" Content="Option 1" />
  101. <RadioButton IsChecked="False" Content="Option 2" />
  102. <RadioButton IsChecked="False" Content="Option 3" />
  103. </StackPanel>
  104. </ScrollViewer>
  105. </TabItem>
  106. <TabItem Header="Images">
  107. <StackPanel Margin="10" Gap="4" HorizontalAlignment="Center">
  108. <TextBlock Text="Carousel" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  109. <TextBlock Text="An items control that displays its items as pages that fill the controls."
  110. FontSize="13"
  111. Foreground="#727272" Margin="0, 0, 0, 10" />
  112. <StackPanel Name="carouselVisual" Orientation="Horizontal">
  113. <Button VerticalAlignment="Center" Margin="5">
  114. <Button.Content>
  115. <Path Fill="Black"
  116. Data="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z" />
  117. </Button.Content>
  118. </Button>
  119. <Carousel Width="400" Height="400">
  120. <Carousel.Transition>
  121. <PageSlide Duration="0.25" />
  122. </Carousel.Transition>
  123. <Image Source="github_icon.png" Width="400" Height="400" />
  124. <Image Source="pattern.jpg" Width="400" Height="400" />
  125. </Carousel>
  126. <Button VerticalAlignment="Center" Margin="5">
  127. <Button.Content>
  128. <Path Fill="Black"
  129. Data="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" />
  130. </Button.Content>
  131. </Button>
  132. </StackPanel>
  133. </StackPanel>
  134. </TabItem>
  135. <TabItem Header="Lists">
  136. <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
  137. <ListBox Items="{Binding Items}" SelectionMode="Multiple">
  138. <ListBox.ItemTemplate>
  139. <DataTemplate DataType="vm:TestItem">
  140. <StackPanel>
  141. <TextBlock Text="{Binding Header}" FontSize="24" />
  142. <TextBlock Text="{Binding SubHeader}" />
  143. </StackPanel>
  144. </DataTemplate>
  145. </ListBox.ItemTemplate>
  146. </ListBox>
  147. <DropDown VerticalAlignment="Center" SelectedIndex="0">
  148. <StackPanel>
  149. <TextBlock Text="Item 1" FontSize="24" />
  150. <TextBlock Text="Item 1 Value" />
  151. </StackPanel>
  152. <StackPanel>
  153. <TextBlock Text="Item 2" FontSize="24" />
  154. <TextBlock Text="Item 2 Value" />
  155. </StackPanel>
  156. </DropDown>
  157. <TreeView Items="{Binding Nodes}">
  158. <TreeView.Styles>
  159. <Style Selector="TreeViewItem">
  160. <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
  161. </Style>
  162. </TreeView.Styles>
  163. <TreeView.ItemTemplate>
  164. <TreeDataTemplate DataType="vm:TestNode" ItemsSource="{Binding Children}">
  165. <StackPanel>
  166. <TextBlock Text="{Binding Header}" FontSize="24" />
  167. <TextBlock Text="{Binding SubHeader}" />
  168. </StackPanel>
  169. </TreeDataTemplate>
  170. </TreeView.ItemTemplate>
  171. </TreeView>
  172. <StackPanel Orientation="Vertical" Gap="4">
  173. <Button Command="{Binding CollapseNodesCommand}">Collapse Nodes</Button>
  174. <Button Command="{Binding ExpandNodesCommand}">Expand Nodes</Button>
  175. </StackPanel>
  176. </StackPanel>
  177. </TabItem>
  178. <TabItem Header="Layout">
  179. <ScrollViewer CanScrollHorizontally="False">
  180. <StackPanel Margin="10" Gap="4">
  181. <TextBlock Text="Grid" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  182. <TextBlock Text="Lays out child controls according to a grid."
  183. FontSize="13"
  184. Foreground="#727272"
  185. Margin="0, 0, 0, 10" />
  186. <Grid ColumnDefinitions="*,*" RowDefinitions="Auto,Auto" Width="300">
  187. <Rectangle Grid.ColumnSpan="2" Fill="#FF5722" Height="200" Margin="2.5" />
  188. <Rectangle Grid.Row="1" Fill="#FF5722" Height="100" Margin="2.5" />
  189. <Rectangle Grid.Row="1" Grid.Column="1" Fill="#FF5722" Height="100" Margin="2.5" />
  190. </Grid>
  191. <TextBlock Text="StackPanel" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  192. <TextBlock Text="A panel which lays out its children horizontally or vertically."
  193. FontSize="13"
  194. Foreground="#727272"
  195. Margin="0, 0, 0, 10" />
  196. <StackPanel Gap="4" Width="300">
  197. <Rectangle Fill="#FFC107" Height="50" />
  198. <Rectangle Fill="#FFC107" Height="50" />
  199. <Rectangle Fill="#FFC107" Height="50" />
  200. </StackPanel>
  201. <TextBlock Text="WrapPanel" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  202. <TextBlock Text="Wraps children to new lines if no space is left:"
  203. FontSize="13"
  204. Foreground="#727272"
  205. Margin="0, 0, 0, 10" />
  206. <WrapPanel>
  207. <Rectangle Fill="#FFC107" Height="50" Width="100" Margin="2.5" />
  208. <Rectangle Fill="#FFC107" Height="100" Width="100" Margin="2.5" />
  209. <Rectangle Fill="#FFC107" Height="50" Width="100" Margin="2.5" />
  210. <Rectangle Fill="#FFC107" Height="50" Width="200" Margin="2.5" />
  211. <Rectangle Fill="#FFC107" Height="100" Width="50" Margin="2.5" />
  212. <Rectangle Fill="#FFC107" Height="50" Width="100" Margin="2.5" />
  213. <Rectangle Fill="#FFC107" Height="50" Width="100" Margin="2.5" />
  214. </WrapPanel>
  215. <TextBlock Text="Canvas" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  216. <TextBlock Text="A panel which lays out its children by explicit coordinates."
  217. FontSize="13"
  218. Foreground="#727272"
  219. Margin="0, 0, 0, 10" />
  220. <Canvas Width="300" Height="200" Background="Yellow">
  221. <Rectangle Fill="Blue" Width="63" Height="41" Canvas.Left="40" Canvas.Top="31" />
  222. <Rectangle Fill="Green" Width="58" Height="58" Canvas.Left="130" Canvas.Top="79" />
  223. </Canvas>
  224. <TextBlock Text="DockPanel" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  225. <TextBlock
  226. Text="A panel which lays docks its children on the sides and optionally fills the remaining space with the last child"
  227. FontSize="13"
  228. Foreground="#727272"
  229. Margin="0, 0, 0, 10" />
  230. <DockPanel Width="300" Height="300">
  231. <Rectangle Fill="Red" Width="25" DockPanel.Dock="Left" />
  232. <Rectangle Fill="Green" Height="25" DockPanel.Dock="Top" />
  233. <Rectangle Fill="Blue" Width="25" DockPanel.Dock="Right" />
  234. <Rectangle Fill="Yellow" Height="25" DockPanel.Dock="Bottom" />
  235. <Rectangle Fill="Pink" />
  236. </DockPanel>
  237. <TextBlock Text="GridSplitter" FontWeight="Medium" FontSize="20" Foreground="#212121" />
  238. <Grid Height="500" Width="500" ColumnDefinitions="*,Auto,*,Auto,*" RowDefinitions="*,Auto,*">
  239. <Border Grid.Column="0" Grid.Row="0" Background="Red" />
  240. <GridSplitter Grid.Column="0" Grid.Row="1" Orientation="Horizontal" />
  241. <Border Grid.Column="0" Grid.Row="2" Background="Yellow" />
  242. <GridSplitter Grid.Column="1" Grid.RowSpan="3" Orientation="Vertical" />
  243. <Border Grid.Column="2" Grid.RowSpan="3" Background="Green" />
  244. <GridSplitter Grid.Column="3" Grid.RowSpan="3" Orientation="Vertical"/>
  245. <Border Grid.Column="4" Grid.Row="0" Background="Blue" />
  246. <GridSplitter Grid.Column="4" Grid.Row="1" Orientation="Horizontal" />
  247. <Border Grid.Column="4" Grid.Row="3" Background="Pink" />
  248. </Grid>
  249. </StackPanel>
  250. </ScrollViewer>
  251. </TabItem>
  252. <TabItem Header="Animations">
  253. <Grid>
  254. <Grid.ColumnDefinitions>
  255. <ColumnDefinition />
  256. <ColumnDefinition />
  257. </Grid.ColumnDefinitions>
  258. <Grid.RowDefinitions>
  259. <RowDefinition />
  260. <RowDefinition Height="Auto" />
  261. </Grid.RowDefinitions>
  262. <Border Width="100" Height="100">
  263. <Border.Background>
  264. <LinearGradientBrush StartPoint="0%,0%" EndPoint="100%,100%">
  265. <GradientStop Color="Red" Offset="0" />
  266. <GradientStop Color="Green" Offset="1" />
  267. </LinearGradientBrush>
  268. </Border.Background>
  269. <TextBox HorizontalAlignment="Center" VerticalAlignment="Center" Text="hello!"></TextBox>
  270. </Border>
  271. <Border Grid.Row="0" Grid.Column="1" Background="Coral" HorizontalAlignment="Center"
  272. VerticalAlignment="Center">
  273. <Image Width="100" Height="100" Source="github_icon.png">
  274. </Image>
  275. </Border>
  276. <Button Grid.Row="1" Grid.Column="1" Content="Animate" HorizontalAlignment="Center"></Button>
  277. </Grid>
  278. </TabItem>
  279. <TabItem Header="Brushes">
  280. <Grid ColumnDefinitions="Auto" RowDefinitions="Auto">
  281. <Border Grid.Row="0" Grid.Column="0" Width="200" Height="200" Margin="10">
  282. <Border.Background>
  283. <VisualBrush TileMode="Tile" Stretch="None" AlignmentX="Left" AlignmentY="Top" SourceRect="0%,0%,100%,100%" DestinationRect="0,0,20,20">
  284. <VisualBrush.Visual>
  285. <StackPanel Orientation="Horizontal">
  286. <StackPanel Orientation="Vertical">
  287. <Rectangle Width="10" Height="10" Fill="DarkGray"/>
  288. <Rectangle Width="10" Height="10" Fill="LightGray"/>
  289. </StackPanel>
  290. <StackPanel Orientation="Vertical">
  291. <Rectangle Width="10" Height="10" Fill="LightGray"/>
  292. <Rectangle Width="10" Height="10" Fill="DarkGray"/>
  293. </StackPanel>
  294. </StackPanel>
  295. </VisualBrush.Visual>
  296. </VisualBrush>
  297. </Border.Background>
  298. </Border>
  299. </Grid>
  300. </TabItem>
  301. <TabItem Header="IScrollable">
  302. <ScrollViewer>
  303. <local:TestScrollable/>
  304. </ScrollViewer>
  305. </TabItem>
  306. <TabItem Header="Mem Leak Repro">
  307. <Grid DataContext="{Binding Shell}">
  308. <StackPanel>
  309. <TabStrip Name="strip" Items="{Binding Documents}" SelectedItem="{Binding SelectedDocument, Mode=TwoWay}" Focusable="false">
  310. <TabStrip.Styles>
  311. <Style Selector="TabStripItem">
  312. <Setter Property="Height" Value="20" />
  313. <Setter Property="Background" Value="#2D2D30" />
  314. <Setter Property="BorderBrush" Value="#3E3E42" />
  315. <Setter Property="BorderThickness" Value="0" />
  316. <Setter Property="Margin" Value="0 0 0 -1" />
  317. <Setter Property="Padding" Value="4 0 4 0" />
  318. <Setter Property="FontSize" Value="12"/>
  319. </Style>
  320. <Style Selector="TabStripItem:pointerover">
  321. <Setter Property="Background" Value="#1c97ea" />
  322. </Style>
  323. <Style Selector="TabStripItem:selected">
  324. <Setter Property="Background" Value="#007ACC" />
  325. </Style>
  326. </TabStrip.Styles>
  327. <TabStrip.DataTemplates>
  328. <DataTemplate>
  329. <StackPanel Orientation="Horizontal" Gap="2">
  330. <TextBlock Text="{Binding Title}" Foreground="WhiteSmoke" Margin="2"/>
  331. <Button Height="14" Width="14">
  332. <Button.Styles>
  333. <Style Selector="Button">
  334. <Setter Property="BorderThickness" Value="0"/>
  335. <Setter Property="Padding" Value="0"/>
  336. <Setter Property="Margin" Value="0"/>
  337. <Setter Property="Background" Value="Transparent" />
  338. </Style>
  339. <Style Selector="Button:pointerover">
  340. <Setter Property="Background" Value="#1c97ea" />
  341. </Style>
  342. </Button.Styles>
  343. <Path Margin="2" Stretch="Uniform" UseLayoutRounding="False" Data="M16,12V4H17V2H7V4H8V12L6,14V16H11.2V22H12.8V16H18V14L16,12Z" Fill="WhiteSmoke" />
  344. </Button>
  345. <Button Height="14" Width="14" Command="{Binding CloseCommand}">
  346. <Button.Styles>
  347. <Style Selector="Button">
  348. <Setter Property="BorderThickness" Value="0"/>
  349. <Setter Property="Padding" Value="0"/>
  350. <Setter Property="Margin" Value="0"/>
  351. <Setter Property="Background" Value="Transparent" />
  352. </Style>
  353. <Style Selector="Button:pointerover">
  354. <Setter Property="Background" Value="#1c97ea" />
  355. </Style>
  356. </Button.Styles>
  357. <Path Margin="2" Stretch="Uniform" UseLayoutRounding="False" Data="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z" Fill="WhiteSmoke" />
  358. </Button>
  359. </StackPanel>
  360. </DataTemplate>
  361. </TabStrip.DataTemplates>
  362. </TabStrip>
  363. <Grid Background="#007ACC" Height="2" />
  364. <Button Content="AddTab" Command="{Binding AddDocumentCommand}" Width="50" Height="30" />
  365. <Button Content="GC.Collecy" Command="{Binding GCCommand}" Width="50" Height="30" />
  366. <TextBox Text="{Binding InstanceCount}" />
  367. <Carousel Items="{Binding Documents}" SelectedIndex="{Binding #strip.SelectedIndex}" IsVirtualized="false">
  368. <Carousel.DataTemplates>
  369. <DataTemplate>
  370. <TextBox Text="{Binding Text}" />
  371. </DataTemplate>
  372. </Carousel.DataTemplates>
  373. </Carousel>
  374. </StackPanel>
  375. </Grid>
  376. </TabItem>
  377. </TabControl>
  378. </Grid>
  379. </Window>