MainWindow.xaml 6.1 KB

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