MainWindow.xaml 7.1 KB

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