MainWindow.xaml 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <Window xmlns="https://github.com/avaloniaui"
  2. xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
  3. x:Class="BindingDemo.MainWindow"
  4. xmlns:vm="clr-namespace:BindingDemo.ViewModels"
  5. xmlns:local="clr-namespace:BindingDemo"
  6. Title="AvaloniaUI Bindings Test"
  7. Width="800"
  8. Height="600">
  9. <Window.Styles>
  10. <Style Selector="TextBlock.h1">
  11. <Setter Property="FontSize" Value="18"/>
  12. </Style>
  13. </Window.Styles>
  14. <Window.Resources>
  15. <vm:TestItem x:Key="SharedItem" StringValue="shared" />
  16. </Window.Resources>
  17. <TabControl>
  18. <TabItem Header="Basic">
  19. <StackPanel Orientation="Vertical">
  20. <StackPanel Orientation="Horizontal">
  21. <StackPanel Margin="18" Spacing="4" Width="200">
  22. <TextBlock FontSize="16" Text="Simple Bindings"/>
  23. <TextBox Watermark="Two Way" UseFloatingWatermark="True" Text="{Binding Path=StringValue}" Name="first"/>
  24. <TextBox Watermark="One Way" UseFloatingWatermark="True" Text="{Binding Path=StringValue, Mode=OneWay}"/>
  25. <TextBox Watermark="One Time" UseFloatingWatermark="True" Text="{Binding Path=StringValue, Mode=OneTime}"/>
  26. </StackPanel>
  27. <StackPanel Margin="18" Spacing="4" Width="200">
  28. <TextBlock FontSize="16" Text="Collection Bindings"/>
  29. <TextBox Watermark="Items[1].StringValue" UseFloatingWatermark="True" Text="{Binding Path=Items[1].StringValue}"/>
  30. <Button Command="{Binding ShuffleItems}">Shuffle</Button>
  31. </StackPanel>
  32. <StackPanel Margin="18" Spacing="4" Width="200">
  33. <TextBlock FontSize="16" Text="Negated Bindings"/>
  34. <TextBox Watermark="Boolean String" UseFloatingWatermark="True" Text="{Binding Path=BooleanString}"/>
  35. <CheckBox IsChecked="{Binding !BooleanString}">!BooleanString</CheckBox>
  36. <CheckBox IsChecked="{Binding !!BooleanString}">!!BooleanString</CheckBox>
  37. </StackPanel>
  38. </StackPanel>
  39. <StackPanel Orientation="Horizontal">
  40. <StackPanel Margin="18" Spacing="4" Width="200" HorizontalAlignment="Left">
  41. <TextBlock FontSize="16" Text="Numeric Bindings"/>
  42. <TextBox Watermark="Double" UseFloatingWatermark="True" Text="{Binding Path=DoubleValue, Mode=TwoWay}"/>
  43. <TextBlock Text="{Binding Path=DoubleValue}"/>
  44. <ProgressBar Maximum="10" Value="{Binding DoubleValue}"/>
  45. </StackPanel>
  46. <StackPanel Margin="18" Spacing="4" Width="200" HorizontalAlignment="Left">
  47. <TextBlock FontSize="16" Text="Binding Sources"/>
  48. <TextBox Watermark="Value of first TextBox" UseFloatingWatermark="True"
  49. Text="{Binding #first.Text, Mode=TwoWay}"/>
  50. <TextBox Watermark="Value of SharedItem.StringValue" UseFloatingWatermark="True"
  51. Text="{Binding StringValue, Source={StaticResource SharedItem}, Mode=TwoWay}"/>
  52. <TextBox Watermark="Value of SharedItem.StringValue (duplicate)" UseFloatingWatermark="True"
  53. Text="{Binding StringValue, Source={StaticResource SharedItem}, Mode=TwoWay}"/>
  54. </StackPanel>
  55. <StackPanel Margin="18" Spacing="4" Width="200" HorizontalAlignment="Left">
  56. <TextBlock FontSize="16" Text="Scheduler"/>
  57. <TextBox Watermark="Background Thread" Text="{Binding CurrentTime, Mode=OneWay}"/>
  58. <TextBlock FontSize="16" Text="Stream Operator"/>
  59. <TextBox Watermark="StreamOperator" Text="{Binding CurrentTimeObservable^, Mode=OneWay}"/>
  60. </StackPanel>
  61. </StackPanel>
  62. </StackPanel>
  63. </TabItem>
  64. <TabItem Header="ListBox">
  65. <StackPanel Orientation="Horizontal">
  66. <StackPanel.DataTemplates>
  67. <DataTemplate DataType="vm:TestItem">
  68. <TextBlock Text="{Binding StringValue}"/>
  69. </DataTemplate>
  70. </StackPanel.DataTemplates>
  71. <StackPanel Margin="18" Spacing="4" Width="200">
  72. <TextBlock FontSize="16" Text="Multiple"/>
  73. <ListBox Items="{Binding Items}" SelectionMode="Multiple" SelectedItems="{Binding SelectedItems}"/>
  74. </StackPanel>
  75. <StackPanel Margin="18" Spacing="4" Width="200">
  76. <TextBlock FontSize="16" Text="Multiple"/>
  77. <ListBox Items="{Binding Items}" SelectionMode="Multiple" SelectedItems="{Binding SelectedItems}"/>
  78. </StackPanel>
  79. <ContentControl Content="{Binding SelectedItems[0]}">
  80. <ContentControl.DataTemplates>
  81. <DataTemplate DataType="vm:TestItem">
  82. <local:TestItemView></local:TestItemView>
  83. </DataTemplate>
  84. </ContentControl.DataTemplates>
  85. </ContentControl>
  86. </StackPanel>
  87. </TabItem>
  88. <TabItem Header="Property Validation">
  89. <StackPanel Orientation="Horizontal">
  90. <StackPanel Margin="18" Spacing="4" MinWidth="200" DataContext="{Binding ExceptionDataValidation}">
  91. <TextBlock FontSize="16" Text="Exception Validation"/>
  92. <TextBox Watermark="Less Than 10" UseFloatingWatermark="True" Text="{Binding Path=LessThan10}"/>
  93. </StackPanel>
  94. <StackPanel Margin="18" Spacing="4" MinWidth="200" DataContext="{Binding IndeiDataValidation}">
  95. <TextBlock FontSize="16" Text="INotifyDataErrorInfo Validation"/>
  96. <TextBox Watermark="Maximum" UseFloatingWatermark="True" Text="{Binding Path=Maximum}"/>
  97. <TextBox Watermark="Value" UseFloatingWatermark="True" Text="{Binding Path=Value}"/>
  98. </StackPanel>
  99. <StackPanel Margin="18" Spacing="4" MinWidth="200" DataContext="{Binding DataAnnotationsValidation}">
  100. <TextBlock FontSize="16" Text="Data Annotations Validation"/>
  101. <TextBox Watermark="Phone #" UseFloatingWatermark="True" Text="{Binding PhoneNumber}"/>
  102. <TextBox Watermark="Less Than 10" UseFloatingWatermark="True" Text="{Binding Path=LessThan10}"/>
  103. </StackPanel>
  104. </StackPanel>
  105. </TabItem>
  106. <TabItem Header="Commands">
  107. <StackPanel Margin="18" Spacing="4" Width="200">
  108. <Button Content="Button" Command="{Binding StringValueCommand}" CommandParameter="Button"/>
  109. <ToggleButton Content="ToggleButton" IsChecked="{Binding BooleanFlag, Mode=OneWay}" Command="{Binding StringValueCommand}" CommandParameter="ToggleButton"/>
  110. <CheckBox Content="CheckBox" IsChecked="{Binding !BooleanFlag, Mode=OneWay}" Command="{Binding StringValueCommand}" CommandParameter="CheckBox"/>
  111. <RadioButton Content="Radio Button" IsChecked="{Binding !!BooleanFlag, Mode=OneWay}" Command="{Binding StringValueCommand}" CommandParameter="RadioButton"/>
  112. <TextBox Text="{Binding Path=StringValue}"/>
  113. <Button Content="Nested View Model Button" Name="NestedTest" Command="{Binding NestedModel.Command}" />
  114. </StackPanel>
  115. </TabItem>
  116. </TabControl>
  117. </Window>