MainWindow.xaml 6.7 KB

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