Browse Source

Merge pull request #10604 from AvaloniaUI/feature/itemssource-update-usages

Update usages of ItemsControl Items/ItemsSource
pull/10689/head
Dan Walmsley 4 years ago
committed by GitHub
parent
commit
70330b5832
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      samples/ControlCatalog/MainView.xaml
  2. 2
      samples/ControlCatalog/Pages/CompositionPage.axaml.cs
  3. 2
      samples/ControlCatalog/Pages/ContextFlyoutPage.xaml
  4. 4
      samples/ControlCatalog/Pages/ContextMenuPage.xaml
  5. 2
      samples/ControlCatalog/Pages/CursorPage.xaml
  6. 12
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  7. 2
      samples/ControlCatalog/Pages/ListBoxPage.xaml
  8. 6
      samples/ControlCatalog/Pages/MenuPage.xaml
  9. 8
      samples/ControlCatalog/Pages/NativeEmbedPage.xaml.cs
  10. 6
      samples/ControlCatalog/Pages/NumericUpDownPage.xaml
  11. 2
      samples/ControlCatalog/Pages/RefreshContainerPage.axaml
  12. 4
      samples/ControlCatalog/Pages/ScrollSnapPage.xaml
  13. 4
      samples/ControlCatalog/Pages/ScrollViewerPage.xaml
  14. 2
      samples/ControlCatalog/Pages/TabStripPage.xaml
  15. 2
      samples/ControlCatalog/Pages/ThemePage.axaml.cs
  16. 2
      samples/ControlCatalog/Pages/TransitioningContentControlPage.axaml
  17. 2
      samples/ControlCatalog/Pages/TreeViewPage.xaml
  18. 2
      samples/IntegrationTestApp/MainWindow.axaml
  19. 2
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml
  20. 2
      src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml
  21. 2
      src/Avalonia.Controls.ColorPicker/Themes/Simple/ColorPicker.xaml
  22. 2
      src/Avalonia.Controls.ColorPicker/Themes/Simple/ColorView.xaml
  23. 1
      src/Avalonia.Controls/ItemsControl.cs
  24. 2
      src/Avalonia.Diagnostics/Diagnostics/Views/ConsoleView.xaml
  25. 6
      src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml
  26. 6
      src/Avalonia.Diagnostics/Diagnostics/Views/EventsPageView.xaml
  27. 2
      src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs
  28. 2
      src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml
  29. 4
      src/Avalonia.Themes.Fluent/Controls/DataValidationErrors.xaml
  30. 6
      src/Avalonia.Themes.Fluent/Controls/ManagedFileChooser.xaml
  31. 4
      src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml
  32. 2
      src/Avalonia.Themes.Simple/Controls/DataValidationErrors.xaml
  33. 6
      src/Avalonia.Themes.Simple/Controls/ManagedFileChooser.xaml
  34. 4
      src/Avalonia.Themes.Simple/Controls/NativeMenuBar.xaml
  35. 2
      src/Windows/Avalonia.Win32/TrayIconImpl.cs
  36. 2
      src/Windows/Avalonia.Win32/Win32NativeToManagedMenuExporter.cs
  37. 20
      tests/Avalonia.Controls.UnitTests/CarouselTests.cs
  38. 88
      tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs
  39. 113
      tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs
  40. 43
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs
  41. 6
      tests/Avalonia.Controls.UnitTests/ListBoxTests_Multiple.cs
  42. 24
      tests/Avalonia.Controls.UnitTests/ListBoxTests_Single.cs
  43. 10
      tests/Avalonia.Controls.UnitTests/MenuItemTests.cs
  44. 2
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs
  45. 4
      tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs
  46. 166
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs
  47. 12
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_AutoSelect.cs
  48. 231
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs
  49. 26
      tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_SelectedValue.cs
  50. 94
      tests/Avalonia.Controls.UnitTests/Primitives/TabStripTests.cs
  51. 154
      tests/Avalonia.Controls.UnitTests/TabControlTests.cs
  52. 116
      tests/Avalonia.Controls.UnitTests/TreeViewTests.cs
  53. 4
      tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs
  54. 2
      tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs
  55. 14
      tests/Avalonia.LeakTests/ControlTests.cs
  56. 8
      tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs
  57. 8
      tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs
  58. 8
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs
  59. 2
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs
  60. 2
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs
  61. 2
      tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs
  62. 2
      tests/Avalonia.ReactiveUI.UnitTests/AutoDataTemplateBindingHookTest.cs

2
samples/ControlCatalog/MainView.xaml

@ -241,7 +241,7 @@
</ComboBox.Items> </ComboBox.Items>
</ComboBox> </ComboBox>
<ComboBox HorizontalAlignment="Stretch" <ComboBox HorizontalAlignment="Stretch"
Items="{Binding WindowStates}" ItemsSource="{Binding WindowStates}"
SelectedItem="{Binding WindowState}" /> SelectedItem="{Binding WindowState}" />
</StackPanel> </StackPanel>
</Flyout> </Flyout>

2
samples/ControlCatalog/Pages/CompositionPage.axaml.cs

@ -32,7 +32,7 @@ public partial class CompositionPage : UserControl
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{ {
base.OnAttachedToVisualTree(e); base.OnAttachedToVisualTree(e);
this.Get<ItemsControl>("Items").Items = CreateColorItems(); this.Get<ItemsControl>("Items").ItemsSource = CreateColorItems();
} }

2
samples/ControlCatalog/Pages/ContextFlyoutPage.xaml

@ -61,7 +61,7 @@
<Border.Styles> <Border.Styles>
<Style Selector="MenuFlyoutPresenter MenuItem" x:DataType="viewModels:MenuItemViewModel"> <Style Selector="MenuFlyoutPresenter MenuItem" x:DataType="viewModels:MenuItemViewModel">
<Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="Items" Value="{Binding Items}"/> <Setter Property="ItemsSource" Value="{Binding Items}"/>
<Setter Property="Command" Value="{Binding Command}"/> <Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/> <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
</Style> </Style>

4
samples/ControlCatalog/Pages/ContextMenuPage.xaml

@ -51,13 +51,13 @@
<Border.Styles> <Border.Styles>
<Style Selector="ContextMenu MenuItem" x:DataType="viewModels:MenuItemViewModel"> <Style Selector="ContextMenu MenuItem" x:DataType="viewModels:MenuItemViewModel">
<Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="Items" Value="{Binding Items}"/> <Setter Property="ItemsSource" Value="{Binding Items}"/>
<Setter Property="Command" Value="{Binding Command}"/> <Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/> <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
</Style> </Style>
</Border.Styles> </Border.Styles>
<Border.ContextMenu> <Border.ContextMenu>
<ContextMenu Items="{Binding MenuItems}" /> <ContextMenu ItemsSource="{Binding MenuItems}" />
</Border.ContextMenu> </Border.ContextMenu>
<TextBlock Text="Dynamically Generated"/> <TextBlock Text="Dynamically Generated"/>
</Border> </Border>

2
samples/ControlCatalog/Pages/CursorPage.xaml

@ -8,7 +8,7 @@
<TextBlock Classes="h2">Defines a cursor (mouse pointer)</TextBlock> <TextBlock Classes="h2">Defines a cursor (mouse pointer)</TextBlock>
</StackPanel> </StackPanel>
<ListBox Grid.Row="1" Items="{Binding StandardCursors}" Margin="0 8 8 8"> <ListBox Grid.Row="1" ItemsSource="{Binding StandardCursors}" Margin="0 8 8 8">
<ListBox.Styles> <ListBox.Styles>
<Style Selector="ListBoxItem"> <Style Selector="ListBoxItem">
<Setter Property="Cursor" Value="{Binding Cursor}" x:DataType="viewModels:StandardCursorModel"/> <Setter Property="Cursor" Value="{Binding Cursor}" x:DataType="viewModels:StandardCursorModel"/>

12
samples/ControlCatalog/Pages/DialogsPage.xaml.cs

@ -106,7 +106,7 @@ namespace ControlCatalog.Pages
Directory = initialDirectory, Directory = initialDirectory,
InitialFileName = initialFileName InitialFileName = initialFileName
}.ShowAsync(GetWindow()); }.ShowAsync(GetWindow());
results.Items = result; results.ItemsSource = result;
resultsVisible.IsVisible = result?.Any() == true; resultsVisible.IsVisible = result?.Any() == true;
}; };
this.Get<Button>("OpenMultipleFiles").Click += async delegate this.Get<Button>("OpenMultipleFiles").Click += async delegate
@ -118,7 +118,7 @@ namespace ControlCatalog.Pages
Directory = lastSelectedDirectory?.Path is {IsAbsoluteUri:true} path ? path.LocalPath : null, Directory = lastSelectedDirectory?.Path is {IsAbsoluteUri:true} path ? path.LocalPath : null,
AllowMultiple = true AllowMultiple = true
}.ShowAsync(GetWindow()); }.ShowAsync(GetWindow());
results.Items = result; results.ItemsSource = result;
resultsVisible.IsVisible = result?.Any() == true; resultsVisible.IsVisible = result?.Any() == true;
}; };
this.Get<Button>("SaveFile").Click += async delegate this.Get<Button>("SaveFile").Click += async delegate
@ -132,7 +132,7 @@ namespace ControlCatalog.Pages
DefaultExtension = filters?.Any() == true ? "txt" : null, DefaultExtension = filters?.Any() == true ? "txt" : null,
InitialFileName = "test.txt" InitialFileName = "test.txt"
}.ShowAsync(GetWindow()); }.ShowAsync(GetWindow());
results.Items = new[] { result }; results.ItemsSource = new[] { result };
resultsVisible.IsVisible = result != null; resultsVisible.IsVisible = result != null;
}; };
this.Get<Button>("SelectFolder").Click += async delegate this.Get<Button>("SelectFolder").Click += async delegate
@ -149,7 +149,7 @@ namespace ControlCatalog.Pages
else else
{ {
SetFolder(await GetStorageProvider().TryGetFolderFromPathAsync(result)); SetFolder(await GetStorageProvider().TryGetFolderFromPathAsync(result));
results.Items = new[] { result }; results.ItemsSource = new[] { result };
resultsVisible.IsVisible = true; resultsVisible.IsVisible = true;
} }
}; };
@ -164,7 +164,7 @@ namespace ControlCatalog.Pages
{ {
AllowDirectorySelection = true AllowDirectorySelection = true
}); });
results.Items = result; results.ItemsSource = result;
resultsVisible.IsVisible = result?.Any() == true; resultsVisible.IsVisible = result?.Any() == true;
}; };
this.Get<Button>("DecoratedWindow").Click += delegate this.Get<Button>("DecoratedWindow").Click += delegate
@ -332,7 +332,7 @@ namespace ControlCatalog.Pages
} }
} }
results.Items = mappedResults; results.ItemsSource = mappedResults;
resultsVisible.IsVisible = mappedResults.Any(); resultsVisible.IsVisible = mappedResults.Any();
} }
} }

2
samples/ControlCatalog/Pages/ListBoxPage.xaml

@ -30,7 +30,7 @@
<Button Command="{Binding RemoveItemCommand}">Remove</Button> <Button Command="{Binding RemoveItemCommand}">Remove</Button>
<Button Command="{Binding SelectRandomItemCommand}">Select Random Item</Button> <Button Command="{Binding SelectRandomItemCommand}">Select Random Item</Button>
</StackPanel> </StackPanel>
<ListBox Items="{Binding Items}" <ListBox ItemsSource="{Binding Items}"
Selection="{Binding Selection}" Selection="{Binding Selection}"
DisplayMemberBinding="{Binding (viewModels:ItemModel).ID, StringFormat='{}Item {0:N0}'}" DisplayMemberBinding="{Binding (viewModels:ItemModel).ID, StringFormat='{}Item {0:N0}'}"
AutoScrollToSelectedItem="{Binding AutoScrollToSelectedItem}" AutoScrollToSelectedItem="{Binding AutoScrollToSelectedItem}"

6
samples/ControlCatalog/Pages/MenuPage.xaml

@ -45,11 +45,11 @@
<StackPanel> <StackPanel>
<TextBlock Classes="h3" Margin="4 8">Dyanamically generated</TextBlock> <TextBlock Classes="h3" Margin="4 8">Dyanamically generated</TextBlock>
<Menu Items="{Binding MenuItems}"> <Menu ItemsSource="{Binding MenuItems}">
<Menu.Styles> <Menu.Styles>
<Style Selector="MenuItem" x:DataType="viewModels:MenuItemViewModel"> <Style Selector="MenuItem" x:DataType="viewModels:MenuItemViewModel">
<Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="Items" Value="{Binding Items}"/> <Setter Property="ItemsSource" Value="{Binding Items}"/>
<Setter Property="Command" Value="{Binding Command}"/> <Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/> <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
</Style> </Style>
@ -68,7 +68,7 @@
<Separator/> <Separator/>
<MenuItem Header="Execu_te Script..." /> <MenuItem Header="Execu_te Script..." />
<Separator/> <Separator/>
<MenuItem Header="_Recent" Items="{Binding RecentItems}"> <MenuItem Header="_Recent" ItemsSource="{Binding RecentItems}">
<MenuItem.Styles> <MenuItem.Styles>
<Style Selector="MenuItem" x:DataType="viewModels:MenuItemViewModel"> <Style Selector="MenuItem" x:DataType="viewModels:MenuItemViewModel">
<Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Header" Value="{Binding Header}"/>

8
samples/ControlCatalog/Pages/NativeEmbedPage.xaml.cs

@ -33,10 +33,10 @@ namespace ControlCatalog.Pages
{ {
new ContextMenu() new ContextMenu()
{ {
Items = new List<MenuItem> Items =
{ {
new MenuItem() { Header = "Test" }, new MenuItem() { Header = "Test" } new MenuItem() { Header = "Test" }, new MenuItem() { Header = "Test" }
} }
}.Open((Control)sender); }.Open((Control)sender);
} }

6
samples/ControlCatalog/Pages/NumericUpDownPage.xaml

@ -27,7 +27,7 @@
</Grid> </Grid>
<Grid Grid.Row="0" Grid.Column="1" Margin="8" ColumnDefinitions="Auto, 120" RowDefinitions="Auto,Auto,Auto,Auto,Auto"> <Grid Grid.Row="0" Grid.Column="1" Margin="8" ColumnDefinitions="Auto, 120" RowDefinitions="Auto,Auto,Auto,Auto,Auto">
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="2">FormatString:</TextBlock> <TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" Margin="2">FormatString:</TextBlock>
<ComboBox Grid.Row="0" Grid.Column="1" Items="{Binding Formats}" SelectedItem="{Binding SelectedFormat}" <ComboBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Formats}" SelectedItem="{Binding SelectedFormat}"
VerticalAlignment="Center" Margin="2"> VerticalAlignment="Center" Margin="2">
<ComboBox.ItemTemplate> <ComboBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -41,11 +41,11 @@
</ComboBox> </ComboBox>
<TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="2">ButtonSpinnerLocation:</TextBlock> <TextBlock Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" Margin="2">ButtonSpinnerLocation:</TextBlock>
<ComboBox Grid.Row="1" Grid.Column="1" Items="{Binding SpinnerLocations}" SelectedItem="{Binding #upDown.ButtonSpinnerLocation}" <ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding SpinnerLocations}" SelectedItem="{Binding #upDown.ButtonSpinnerLocation}"
VerticalAlignment="Center" Margin="2"/> VerticalAlignment="Center" Margin="2"/>
<TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="2">CultureInfo:</TextBlock> <TextBlock Grid.Row="2" Grid.Column="0" VerticalAlignment="Center" Margin="2">CultureInfo:</TextBlock>
<ComboBox x:Name="CultureSelector" Grid.Row="2" Grid.Column="1" Items="{Binding Cultures}" <ComboBox x:Name="CultureSelector" Grid.Row="2" Grid.Column="1" ItemsSource="{Binding Cultures}"
VerticalAlignment="Center" Margin="2"/> VerticalAlignment="Center" Margin="2"/>
<TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="2">Watermark:</TextBlock> <TextBlock Grid.Row="3" Grid.Column="0" VerticalAlignment="Center" Margin="2">Watermark:</TextBlock>

2
samples/ControlCatalog/Pages/RefreshContainerPage.axaml

@ -21,7 +21,7 @@
Margin="5"> Margin="5">
<ListBox HorizontalAlignment="Stretch" <ListBox HorizontalAlignment="Stretch"
VerticalAlignment="Top" VerticalAlignment="Top"
Items="{Binding Items}"/> ItemsSource="{Binding Items}"/>
</RefreshContainer> </RefreshContainer>
</DockPanel> </DockPanel>
</UserControl> </UserControl>

4
samples/ControlCatalog/Pages/ScrollSnapPage.xaml

@ -16,14 +16,14 @@
<StackPanel Orientation="Vertical" <StackPanel Orientation="Vertical"
Spacing="4"> Spacing="4">
<TextBlock Text="Snap Point Type" /> <TextBlock Text="Snap Point Type" />
<ComboBox Items="{Binding AvailableSnapPointsType}" <ComboBox ItemsSource="{Binding AvailableSnapPointsType}"
SelectedItem="{Binding SnapPointsType}" /> SelectedItem="{Binding SnapPointsType}" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" <StackPanel Orientation="Vertical"
Spacing="4"> Spacing="4">
<TextBlock Text="Snap Point Alignment" /> <TextBlock Text="Snap Point Alignment" />
<ComboBox Items="{Binding AvailableSnapPointsAlignment}" <ComboBox ItemsSource="{Binding AvailableSnapPointsAlignment}"
SelectedItem="{Binding SnapPointsAlignment}" /> SelectedItem="{Binding SnapPointsAlignment}" />
</StackPanel> </StackPanel>

4
samples/ControlCatalog/Pages/ScrollViewerPage.xaml

@ -13,12 +13,12 @@
<StackPanel Orientation="Vertical" Spacing="4"> <StackPanel Orientation="Vertical" Spacing="4">
<TextBlock Text="Horizontal Scroll" /> <TextBlock Text="Horizontal Scroll" />
<ComboBox Items="{Binding AvailableVisibility}" SelectedItem="{Binding HorizontalScrollVisibility}" /> <ComboBox ItemsSource="{Binding AvailableVisibility}" SelectedItem="{Binding HorizontalScrollVisibility}" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Spacing="4"> <StackPanel Orientation="Vertical" Spacing="4">
<TextBlock Text="Vertical Scroll" /> <TextBlock Text="Vertical Scroll" />
<ComboBox Items="{Binding AvailableVisibility}" SelectedItem="{Binding VerticalScrollVisibility}" /> <ComboBox ItemsSource="{Binding AvailableVisibility}" SelectedItem="{Binding VerticalScrollVisibility}" />
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>

2
samples/ControlCatalog/Pages/TabStripPage.xaml

@ -18,7 +18,7 @@
<Separator Margin="0 16"/> <Separator Margin="0 16"/>
<TextBlock Classes="h1">Dynamically generated</TextBlock> <TextBlock Classes="h1">Dynamically generated</TextBlock>
<TabStrip Items="{Binding Tabs}"> <TabStrip ItemsSource="{Binding Tabs}">
<TabStrip.Styles> <TabStrip.Styles>
<Style Selector="TabStripItem" x:DataType="viewModels:TabControlPageViewModelItem"> <Style Selector="TabStripItem" x:DataType="viewModels:TabControlPageViewModelItem">
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/> <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>

2
samples/ControlCatalog/Pages/ThemePage.axaml.cs

@ -12,7 +12,7 @@ namespace ControlCatalog.Pages
{ {
InitializeComponent(); InitializeComponent();
Selector.Items = new[] Selector.ItemsSource = new[]
{ {
ThemeVariant.Default, ThemeVariant.Default,
ThemeVariant.Dark, ThemeVariant.Dark,

2
samples/ControlCatalog/Pages/TransitioningContentControlPage.axaml

@ -53,7 +53,7 @@
<StackPanel Margin="5" Spacing="5" Grid.IsSharedSizeScope="True"> <StackPanel Margin="5" Spacing="5" Grid.IsSharedSizeScope="True">
<HeaderedContentControl Header="Select a transition"> <HeaderedContentControl Header="Select a transition">
<ComboBox Items="{Binding PageTransitions}" SelectedItem="{Binding SelectedTransition}" /> <ComboBox ItemsSource="{Binding PageTransitions}" SelectedItem="{Binding SelectedTransition}" />
</HeaderedContentControl> </HeaderedContentControl>
<HeaderedContentControl Header="Duration"> <HeaderedContentControl Header="Duration">
<NumericUpDown Value="{Binding Duration}" Increment="250" Minimum="100" /> <NumericUpDown Value="{Binding Duration}" Increment="250" Minimum="100" />

2
samples/ControlCatalog/Pages/TreeViewPage.xaml

@ -11,7 +11,7 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
Spacing="16"> Spacing="16">
<StackPanel Orientation="Vertical" Spacing="8"> <StackPanel Orientation="Vertical" Spacing="8">
<TreeView Items="{Binding Items}" SelectedItems="{Binding SelectedItems}" SelectionMode="{Binding SelectionMode}" Width="250" Height="350"> <TreeView ItemsSource="{Binding Items}" SelectedItems="{Binding SelectedItems}" SelectionMode="{Binding SelectionMode}" Width="250" Height="350">
<TreeView.ItemTemplate> <TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding Children}"> <TreeDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Header}"/> <TextBlock Text="{Binding Header}"/>

2
samples/IntegrationTestApp/MainWindow.axaml

@ -109,7 +109,7 @@
<StackPanel DockPanel.Dock="Bottom"> <StackPanel DockPanel.Dock="Bottom">
<Button Name="ListBoxSelectionClear">Clear Selection</Button> <Button Name="ListBoxSelectionClear">Clear Selection</Button>
</StackPanel> </StackPanel>
<ListBox Name="BasicListBox" Items="{Binding ListBoxItems}" SelectionMode="Multiple"/> <ListBox Name="BasicListBox" ItemsSource="{Binding ListBoxItems}" SelectionMode="Multiple"/>
</DockPanel> </DockPanel>
</TabItem> </TabItem>

2
src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorPicker.xaml

@ -165,7 +165,7 @@
</TabItem.Header> </TabItem.Header>
<ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}" <ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}"
ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}" ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}"
Items="{TemplateBinding PaletteColors}" ItemsSource="{TemplateBinding PaletteColors}"
SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}" SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}"
UseLayoutRounding="False" UseLayoutRounding="False"
Margin="12"> Margin="12">

2
src/Avalonia.Controls.ColorPicker/Themes/Fluent/ColorView.xaml

@ -414,7 +414,7 @@
</TabItem.Header> </TabItem.Header>
<ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}" <ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}"
ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}" ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}"
Items="{TemplateBinding PaletteColors}" ItemsSource="{TemplateBinding PaletteColors}"
SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}" SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}"
UseLayoutRounding="False" UseLayoutRounding="False"
Margin="12"> Margin="12">

2
src/Avalonia.Controls.ColorPicker/Themes/Simple/ColorPicker.xaml

@ -165,7 +165,7 @@
</TabItem.Header> </TabItem.Header>
<ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}" <ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}"
ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}" ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}"
Items="{TemplateBinding PaletteColors}" ItemsSource="{TemplateBinding PaletteColors}"
SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}" SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}"
UseLayoutRounding="False" UseLayoutRounding="False"
Margin="12"> Margin="12">

2
src/Avalonia.Controls.ColorPicker/Themes/Simple/ColorView.xaml

@ -376,7 +376,7 @@
</TabItem.Header> </TabItem.Header>
<ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}" <ListBox Theme="{StaticResource ColorViewPaletteListBoxTheme}"
ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}" ItemContainerTheme="{StaticResource ColorViewPaletteListBoxItemTheme}"
Items="{TemplateBinding PaletteColors}" ItemsSource="{TemplateBinding PaletteColors}"
SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}" SelectedItem="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DoNothingForNullConverter}, Mode=TwoWay}"
UseLayoutRounding="False" UseLayoutRounding="False"
Margin="12"> Margin="12">

1
src/Avalonia.Controls/ItemsControl.cs

@ -2,6 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using Avalonia.Automation.Peers; using Avalonia.Automation.Peers;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls.Generators; using Avalonia.Controls.Generators;

2
src/Avalonia.Diagnostics/Diagnostics/Views/ConsoleView.xaml

@ -40,7 +40,7 @@
BorderBrush="{DynamicResource ThemeControlMidBrush}" BorderBrush="{DynamicResource ThemeControlMidBrush}"
BorderThickness="0,0,0,1" BorderThickness="0,0,0,1"
FontFamily="/Assets/Fonts/SourceSansPro-Regular.ttf" FontFamily="/Assets/Fonts/SourceSansPro-Regular.ttf"
Items="{Binding History}"> ItemsSource="{Binding History}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">

6
src/Avalonia.Diagnostics/Diagnostics/Views/ControlDetailsView.xaml

@ -124,7 +124,7 @@
</Grid> </Grid>
<ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled"> <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Disabled">
<ItemsControl Items="{Binding AppliedStyles}" > <ItemsControl ItemsSource="{Binding AppliedStyles}" >
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderThickness="0,0,0,1" BorderBrush="#6C6C6C" Opacity="{Binding IsActive, Converter={StaticResource BoolToOpacity}}"> <Border BorderThickness="0,0,0,1" BorderBrush="#6C6C6C" Opacity="{Binding IsActive, Converter={StaticResource BoolToOpacity}}">
@ -142,7 +142,7 @@
<TextBlock Grid.Row="0" Text="{Binding Name}" /> <TextBlock Grid.Row="0" Text="{Binding Name}" />
</Expander.Header> </Expander.Header>
<ItemsControl Margin="20,0,0,0" Grid.Row="1" Items="{Binding Setters}"> <ItemsControl Margin="20,0,0,0" Grid.Row="1" ItemsSource="{Binding Setters}">
<ItemsControl.Styles> <ItemsControl.Styles>
<Style Selector="TextBlock.property-name"> <Style Selector="TextBlock.property-name">
@ -253,7 +253,7 @@
</ScrollViewer> </ScrollViewer>
<Expander Header="Pseudo Classes" Grid.Row="2"> <Expander Header="Pseudo Classes" Grid.Row="2">
<ItemsControl Items="{Binding PseudoClasses}"> <ItemsControl ItemsSource="{Binding PseudoClasses}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<WrapPanel /> <WrapPanel />

6
src/Avalonia.Diagnostics/Diagnostics/Views/EventsPageView.xaml

@ -45,7 +45,7 @@
UseWholeWordFilter="{Binding UseWholeWordFilter}" UseWholeWordFilter="{Binding UseWholeWordFilter}"
UseRegexFilter="{Binding UseRegexFilter}" /> UseRegexFilter="{Binding UseRegexFilter}" />
<TreeView Grid.Row="1" Items="{Binding Nodes}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}" > <TreeView Grid.Row="1" ItemsSource="{Binding Nodes}" SelectedItem="{Binding SelectedNode, Mode=TwoWay}" >
<TreeView.DataTemplates> <TreeView.DataTemplates>
<TreeDataTemplate DataType="vm:EventTreeNodeBase" <TreeDataTemplate DataType="vm:EventTreeNodeBase"
ItemsSource="{Binding Children}"> ItemsSource="{Binding Children}">
@ -71,7 +71,7 @@
<Grid RowDefinitions="*,4,2*,Auto" Grid.Column="2"> <Grid RowDefinitions="*,4,2*,Auto" Grid.Column="2">
<ListBox Name="EventsList" Items="{Binding RecordedEvents}" <ListBox Name="EventsList" ItemsSource="{Binding RecordedEvents}"
SelectedItem="{Binding SelectedEvent, Mode=TwoWay}"> SelectedItem="{Binding SelectedEvent, Mode=TwoWay}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
@ -108,7 +108,7 @@
<DockPanel Grid.Row="2" LastChildFill="True"> <DockPanel Grid.Row="2" LastChildFill="True">
<TextBlock DockPanel.Dock="Top" FontSize="16" Text="Event chain:" /> <TextBlock DockPanel.Dock="Top" FontSize="16" Text="Event chain:" />
<ListBox Items="{Binding SelectedEvent.EventChain}"> <ListBox ItemsSource="{Binding SelectedEvent.EventChain}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<ListBoxItem Classes.handled="{Binding Handled}"> <ListBoxItem Classes.handled="{Binding Handled}">

2
src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs

@ -221,7 +221,7 @@ namespace Avalonia.Diagnostics.Views
return CreateControl<ComboBox>( return CreateControl<ComboBox>(
SelectingItemsControl.SelectedItemProperty, init: c => SelectingItemsControl.SelectedItemProperty, init: c =>
{ {
c.Items = Enum.GetValues(propertyType); c.ItemsSource = Enum.GetValues(propertyType);
}); });
var tb = CreateControl<CommitTextBox>( var tb = CreateControl<CommitTextBox>(

2
src/Avalonia.Diagnostics/Diagnostics/Views/TreePageView.xaml

@ -6,7 +6,7 @@
<Grid ColumnDefinitions="0.35*,4,0.65*"> <Grid ColumnDefinitions="0.35*,4,0.65*">
<TreeView Name="tree" <TreeView Name="tree"
BorderThickness="0" BorderThickness="0"
Items="{Binding Nodes}" ItemsSource="{Binding Nodes}"
SelectedItem="{Binding SelectedNode, Mode=TwoWay}"> SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
<TreeView.DataTemplates> <TreeView.DataTemplates>
<TreeDataTemplate DataType="vm:TreeNode" <TreeDataTemplate DataType="vm:TreeNode"

4
src/Avalonia.Themes.Fluent/Controls/DataValidationErrors.xaml

@ -50,7 +50,7 @@
<DataTemplate> <DataTemplate>
<ItemsControl x:DataType="DataValidationErrors" <ItemsControl x:DataType="DataValidationErrors"
Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}" Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}"
Items="{Binding}"> ItemsSource="{Binding}">
<ItemsControl.Styles> <ItemsControl.Styles>
<Style Selector="TextBlock"> <Style Selector="TextBlock">
<Setter Property="TextWrapping" Value="Wrap" /> <Setter Property="TextWrapping" Value="Wrap" />
@ -98,7 +98,7 @@
</Style> </Style>
</Panel.Styles> </Panel.Styles>
<ToolTip.Tip> <ToolTip.Tip>
<ItemsControl Items="{Binding}" x:DataType="collections:IEnumerable" /> <ItemsControl ItemsSource="{Binding}" x:DataType="collections:IEnumerable" />
</ToolTip.Tip> </ToolTip.Tip>
<Path Width="14" <Path Width="14"
Height="14" Height="14"

6
src/Avalonia.Themes.Fluent/Controls/ManagedFileChooser.xaml

@ -136,7 +136,7 @@
x:DataType="internal:ManagedFileChooserViewModel"> x:DataType="internal:ManagedFileChooserViewModel">
<ControlTemplate> <ControlTemplate>
<DockPanel> <DockPanel>
<ListBox x:Name="PART_QuickLinks" DockPanel.Dock="Left" Items="{Binding QuickLinks}" SelectedIndex="{Binding QuickLinksSelectedIndex}" Focusable="False"> <ListBox x:Name="PART_QuickLinks" DockPanel.Dock="Left" ItemsSource="{Binding QuickLinks}" SelectedIndex="{Binding QuickLinksSelectedIndex}" Focusable="False">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
<StackPanel Spacing="4" Orientation="Horizontal" Background="Transparent"> <StackPanel Spacing="4" Orientation="Horizontal" Background="Transparent">
@ -173,7 +173,7 @@
<DockPanel DockPanel.Dock="Top" Margin="0,0,0,4"> <DockPanel DockPanel.Dock="Top" Margin="0,0,0,4">
<ComboBox DockPanel.Dock="Right" <ComboBox DockPanel.Dock="Right"
IsVisible="{Binding ShowFilters}" IsVisible="{Binding ShowFilters}"
Items="{Binding Filters}" ItemsSource="{Binding Filters}"
SelectedItem="{Binding SelectedFilter}" /> SelectedItem="{Binding SelectedFilter}" />
<TextBox Text="{Binding FileName}" Watermark="File name" IsVisible="{Binding !SelectingFolder}" /> <TextBox Text="{Binding FileName}" Watermark="File name" IsVisible="{Binding !SelectingFolder}" />
</DockPanel> </DockPanel>
@ -220,7 +220,7 @@
<TextBlock Grid.Column="8" Text="Size" /> <TextBlock Grid.Column="8" Text="Size" />
</Grid> </Grid>
<ListBox x:Name="PART_Files" <ListBox x:Name="PART_Files"
Items="{Binding Items}" ItemsSource="{Binding Items}"
Margin="0 5" Margin="0 5"
SelectionMode="{Binding SelectionMode}" SelectionMode="{Binding SelectionMode}"
SelectedItems="{Binding SelectedItems}" SelectedItems="{Binding SelectedItems}"

4
src/Avalonia.Themes.Fluent/Controls/NativeMenuBar.xaml

@ -7,13 +7,13 @@
<ControlTemplate> <ControlTemplate>
<Menu <Menu
IsVisible="{Binding !$parent[TopLevel].(NativeMenu.IsNativeMenuExported)}" IsVisible="{Binding !$parent[TopLevel].(NativeMenu.IsNativeMenuExported)}"
Items="{Binding $parent[TopLevel].(NativeMenu.Menu).Items}"> ItemsSource="{Binding $parent[TopLevel].(NativeMenu.Menu).Items}">
<Menu.Styles> <Menu.Styles>
<Style Selector="MenuItem" x:DataType="NativeMenuItem"> <Style Selector="MenuItem" x:DataType="NativeMenuItem">
<Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/> <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
<Setter Property="InputGesture" Value="{Binding Gesture}"/> <Setter Property="InputGesture" Value="{Binding Gesture}"/>
<Setter Property="Items" Value="{Binding Menu.Items}"/> <Setter Property="ItemsSource" Value="{Binding Menu.Items}"/>
<Setter Property="Command" Value="{Binding Command}"/> <Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/> <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
<Setter Property="(NativeMenuBar.EnableMenuItemClickForwarding)" Value="True"/> <Setter Property="(NativeMenuBar.EnableMenuItemClickForwarding)" Value="True"/>

2
src/Avalonia.Themes.Simple/Controls/DataValidationErrors.xaml

@ -35,7 +35,7 @@
</Canvas.Styles> </Canvas.Styles>
<ToolTip.Tip> <ToolTip.Tip>
<ItemsControl x:DataType="DataValidationErrors" <ItemsControl x:DataType="DataValidationErrors"
Items="{Binding}" /> ItemsSource="{Binding}" />
</ToolTip.Tip> </ToolTip.Tip>
<Path Data="M14,7 A7,7 0 0,0 0,7 M0,7 A7,7 0 1,0 14,7 M7,3l0,5 M7,9l0,2" <Path Data="M14,7 A7,7 0 0,0 0,7 M0,7 A7,7 0 1,0 14,7 M7,3l0,5 M7,9l0,2"
Stroke="{DynamicResource ErrorBrush}" Stroke="{DynamicResource ErrorBrush}"

6
src/Avalonia.Themes.Simple/Controls/ManagedFileChooser.xaml

@ -101,7 +101,7 @@
<ComboBox Margin="0,5,0,0" <ComboBox Margin="0,5,0,0"
DockPanel.Dock="Bottom" DockPanel.Dock="Bottom"
IsVisible="{Binding ShowFilters}" IsVisible="{Binding ShowFilters}"
Items="{Binding Filters}" ItemsSource="{Binding Filters}"
SelectedItem="{Binding SelectedFilter}" /> SelectedItem="{Binding SelectedFilter}" />
<TextBox DockPanel.Dock="Bottom" <TextBox DockPanel.Dock="Bottom"
@ -114,7 +114,7 @@
BorderBrush="Transparent" BorderBrush="Transparent"
DockPanel.Dock="Left" DockPanel.Dock="Left"
Focusable="False" Focusable="False"
Items="{Binding QuickLinks}" ItemsSource="{Binding QuickLinks}"
SelectedIndex="{Binding QuickLinksSelectedIndex}"> SelectedIndex="{Binding QuickLinksSelectedIndex}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate>
@ -160,7 +160,7 @@
</Grid> </Grid>
<ListBox x:Name="PART_Files" <ListBox x:Name="PART_Files"
Margin="0,5" Margin="0,5"
Items="{Binding Items}" ItemsSource="{Binding Items}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedItems="{Binding SelectedItems}" SelectedItems="{Binding SelectedItems}"
SelectionMode="{Binding SelectionMode}"> SelectionMode="{Binding SelectionMode}">

4
src/Avalonia.Themes.Simple/Controls/NativeMenuBar.xaml

@ -7,13 +7,13 @@
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate> <ControlTemplate>
<Menu IsVisible="{Binding !$parent[TopLevel].(NativeMenu.IsNativeMenuExported)}" <Menu IsVisible="{Binding !$parent[TopLevel].(NativeMenu.IsNativeMenuExported)}"
Items="{Binding $parent[TopLevel].(NativeMenu.Menu).Items}"> ItemsSource="{Binding $parent[TopLevel].(NativeMenu.Menu).Items}">
<Menu.Styles> <Menu.Styles>
<Style Selector="MenuItem" x:DataType="NativeMenuItem"> <Style Selector="MenuItem" x:DataType="NativeMenuItem">
<Setter Property="Header" Value="{Binding Header}"/> <Setter Property="Header" Value="{Binding Header}"/>
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/> <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
<Setter Property="InputGesture" Value="{Binding Gesture}"/> <Setter Property="InputGesture" Value="{Binding Gesture}"/>
<Setter Property="Items" Value="{Binding Menu.Items}"/> <Setter Property="ItemsSource" Value="{Binding Menu.Items}"/>
<Setter Property="Command" Value="{Binding Command}"/> <Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="CommandParameter" Value="{Binding CommandParameter}"/> <Setter Property="CommandParameter" Value="{Binding CommandParameter}"/>
<Setter Property="(NativeMenuBar.EnableMenuItemClickForwarding)" Value="True"/> <Setter Property="(NativeMenuBar.EnableMenuItemClickForwarding)" Value="True"/>

2
src/Windows/Avalonia.Win32/TrayIconImpl.cs

@ -150,7 +150,7 @@ namespace Avalonia.Win32
TransparencyLevelHint = WindowTransparencyLevel.Transparent, TransparencyLevelHint = WindowTransparencyLevel.Transparent,
Content = new TrayIconMenuFlyoutPresenter() Content = new TrayIconMenuFlyoutPresenter()
{ {
Items = menuItems ItemsSource = menuItems
} }
}; };

2
src/Windows/Avalonia.Win32/Win32NativeToManagedMenuExporter.cs

@ -39,7 +39,7 @@ namespace Avalonia.Win32
if (item.Menu != null) if (item.Menu != null)
{ {
newItem.Items = Populate(item.Menu); newItem.ItemsSource = Populate(item.Menu);
} }
else if (item.HasClickHandlers && item is INativeMenuItemExporterEventsImplBridge bridge) else if (item.HasClickHandlers && item is INativeMenuItemExporterEventsImplBridge bridge)
{ {

20
tests/Avalonia.Controls.UnitTests/CarouselTests.cs

@ -23,7 +23,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = new[] ItemsSource = new[]
{ {
"Foo", "Foo",
"Bar" "Bar"
@ -43,7 +43,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = new[] ItemsSource = new[]
{ {
"Foo", "Foo",
"Bar" "Bar"
@ -73,7 +73,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);
@ -88,7 +88,7 @@ namespace Avalonia.Controls.UnitTests
newItems.RemoveAt(0); newItems.RemoveAt(0);
Layout(target); Layout(target);
target.Items = newItems; target.ItemsSource = newItems;
Layout(target); Layout(target);
child = GetContainerTextBlock(target.GetRealizedContainers().Single()); child = GetContainerTextBlock(target.GetRealizedContainers().Single());
@ -104,7 +104,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);
@ -133,7 +133,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);
@ -144,7 +144,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal("Foo", child.Text); Assert.Equal("Foo", child.Text);
target.Items = null; target.ItemsSource = null;
Layout(target); Layout(target);
var numChildren = target.GetRealizedContainers().Count(); var numChildren = target.GetRealizedContainers().Count();
@ -166,7 +166,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = items, ItemsSource = items,
SelectedIndex = 2 SelectedIndex = 2
}; };
@ -193,7 +193,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);
@ -225,7 +225,7 @@ namespace Avalonia.Controls.UnitTests
var target = new Carousel var target = new Carousel
{ {
Template = CarouselTemplate(), Template = CarouselTemplate(),
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);

88
tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs

@ -23,7 +23,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ComboBox var target = new ComboBox
{ {
Items = new[] { "Foo", "Bar" }, ItemsSource = new[] { "Foo", "Bar" },
}; };
_helper.Down(target); _helper.Down(target);
@ -43,7 +43,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ComboBox var target = new ComboBox
{ {
Items = new[] { "Foo", "Bar" }, ItemsSource = new[] { "Foo", "Bar" },
}; };
_helper.Down(target); _helper.Down(target);
@ -66,15 +66,14 @@ namespace Avalonia.Controls.UnitTests
{ {
using (UnitTestApplication.Start(TestServices.RealFocus)) using (UnitTestApplication.Start(TestServices.RealFocus))
{ {
var items = new[]
{
new ComboBoxItem() { Content = "bla" },
new ComboBoxItem() { Content = "dd" },
new ComboBoxItem() { Content = "sdf", IsEnabled = false }
};
var target = new ComboBox var target = new ComboBox
{ {
Items = items, Items =
{
new ComboBoxItem() { Content = "bla" },
new ComboBoxItem() { Content = "dd" },
new ComboBoxItem() { Content = "sdf", IsEnabled = false }
},
Template = GetTemplate(), Template = GetTemplate(),
WrapSelection = true WrapSelection = true
}; };
@ -104,15 +103,14 @@ namespace Avalonia.Controls.UnitTests
{ {
using (UnitTestApplication.Start(TestServices.RealFocus)) using (UnitTestApplication.Start(TestServices.RealFocus))
{ {
var items = new[]
{
new ComboBoxItem() { Content = "bla" },
new ComboBoxItem() { Content = "dd", IsEnabled = false },
new ComboBoxItem() { Content = "sdf" }
};
var target = new ComboBox var target = new ComboBox
{ {
Items = items, Items =
{
new ComboBoxItem() { Content = "bla" },
new ComboBoxItem() { Content = "dd", IsEnabled = false },
new ComboBoxItem() { Content = "sdf" }
},
Template = GetTemplate() Template = GetTemplate()
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -139,10 +137,9 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void SelectionBoxItem_Is_Rectangle_With_VisualBrush_When_Selection_Is_Control() public void SelectionBoxItem_Is_Rectangle_With_VisualBrush_When_Selection_Is_Control()
{ {
var items = new[] { new Canvas() };
var target = new ComboBox var target = new ComboBox
{ {
Items = items, Items = { new Canvas() },
SelectedIndex = 0, SelectedIndex = 0,
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -152,7 +149,7 @@ namespace Avalonia.Controls.UnitTests
var brush = rectangle.Fill as VisualBrush; var brush = rectangle.Fill as VisualBrush;
Assert.NotNull(brush); Assert.NotNull(brush);
Assert.Same(items[0], brush.Visual); Assert.Same(target.Items[0], brush.Visual);
} }
[Fact] [Fact]
@ -160,7 +157,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ComboBox var target = new ComboBox
{ {
Items = new[] { new Canvas() }, Items = { new Canvas() },
SelectedIndex = 0, SelectedIndex = 0,
Template = GetTemplate(), Template = GetTemplate(),
}; };
@ -218,7 +215,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ComboBox var target = new ComboBox
{ {
Items = new[] { new Canvas() }, Items = { new Canvas() },
SelectedIndex = 0, SelectedIndex = 0,
Template = GetTemplate(), Template = GetTemplate(),
}; };
@ -257,7 +254,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ComboBox var target = new ComboBox
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items.Select(x => new ComboBoxItem { Content = x }).ToList(), ItemsSource = items.Select(x => new ComboBoxItem { Content = x })
}; };
target.ApplyTemplate(); target.ApplyTemplate();
@ -326,7 +323,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ComboBox var target = new ComboBox
{ {
Items = new[] { new Canvas() }, Items = { new Canvas() },
SelectedIndex = 0, SelectedIndex = 0,
Template = GetTemplate(), Template = GetTemplate(),
}; };
@ -363,17 +360,16 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void FlowDirection_Of_RectangleContent_Shuold_Be_LeftToRight() public void FlowDirection_Of_RectangleContent_Shuold_Be_LeftToRight()
{ {
var items = new[]
{
new ComboBoxItem()
{
Content = new Control()
}
};
var target = new ComboBox var target = new ComboBox
{ {
FlowDirection = FlowDirection.RightToLeft, FlowDirection = FlowDirection.RightToLeft,
Items = items, Items =
{
new ComboBoxItem()
{
Content = new Control()
}
},
Template = GetTemplate() Template = GetTemplate()
}; };
@ -393,16 +389,15 @@ namespace Avalonia.Controls.UnitTests
{ {
Child = new Control() Child = new Control()
}; };
var items = new[]
{
new ComboBoxItem()
{
Content = parentContent.Child
}
};
var target = new ComboBox var target = new ComboBox
{ {
Items = items, Items =
{
new ComboBoxItem()
{
Content = parentContent.Child
}
},
Template = GetTemplate() Template = GetTemplate()
}; };
@ -428,17 +423,16 @@ namespace Avalonia.Controls.UnitTests
{ {
Child = new Control() Child = new Control()
}; };
var items = new[]
{
new ComboBoxItem()
{
Content = parentContent.Child
}
};
var target = new ComboBox var target = new ComboBox
{ {
FlowDirection = FlowDirection.RightToLeft, FlowDirection = FlowDirection.RightToLeft,
Items = items, Items =
{
new ComboBoxItem()
{
Content = parentContent.Child
}
},
Template = GetTemplate() Template = GetTemplate()
}; };

113
tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs

@ -65,7 +65,7 @@ namespace Avalonia.Controls.UnitTests
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()),
}; };
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -84,7 +84,7 @@ namespace Avalonia.Controls.UnitTests
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()),
}; };
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -106,7 +106,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl(); var target = new ItemsControl();
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -119,7 +119,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl(); var target = new ItemsControl();
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter!.ApplyTemplate(); target.Presenter!.ApplyTemplate();
@ -132,7 +132,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl(); var target = new ItemsControl();
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -151,7 +151,7 @@ namespace Avalonia.Controls.UnitTests
}; };
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -174,7 +174,7 @@ namespace Avalonia.Controls.UnitTests
target.TemplatedParent = templatedParent; target.TemplatedParent = templatedParent;
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
root.ApplyTemplate(); root.ApplyTemplate();
target.ApplyTemplate(); target.ApplyTemplate();
@ -211,7 +211,7 @@ namespace Avalonia.Controls.UnitTests
var child = new Control(); var child = new Control();
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { child }; target.Items.Add(child);
root.LayoutManager.ExecuteInitialLayoutPass(); root.LayoutManager.ExecuteInitialLayoutPass();
Assert.Equal(target, child.Parent); Assert.Equal(target, child.Parent);
@ -228,7 +228,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl var target = new ItemsControl
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
var root = new TestRoot(true, target); var root = new TestRoot(true, target);
@ -314,9 +314,9 @@ namespace Avalonia.Controls.UnitTests
var child = new Control(); var child = new Control();
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { child }; target.Items.Add(child);
target.ApplyTemplate(); target.ApplyTemplate();
target.Items = null; target.Items.Clear();
Assert.Null(child.Parent); Assert.Null(child.Parent);
Assert.Null(((ILogical)child).LogicalParent); Assert.Null(((ILogical)child).LogicalParent);
@ -343,10 +343,9 @@ namespace Avalonia.Controls.UnitTests
public void Adding_String_Item_Should_Make_ContentPresenter_Appear_In_LogicalChildren() public void Adding_String_Item_Should_Make_ContentPresenter_Appear_In_LogicalChildren()
{ {
var target = new ItemsControl(); var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -355,25 +354,6 @@ namespace Avalonia.Controls.UnitTests
Assert.IsType<ContentPresenter>(logical.LogicalChildren[0]); Assert.IsType<ContentPresenter>(logical.LogicalChildren[0]);
} }
[Fact]
public void Setting_Items_To_Null_Should_Remove_LogicalChildren()
{
var target = new ItemsControl();
var child = new Control();
target.Template = GetTemplate();
target.Items = new[] { "Foo" };
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
Assert.NotEmpty(target.GetLogicalChildren());
target.Items = null;
Assert.Equal(new ILogical[0], target.GetLogicalChildren());
}
[Fact] [Fact]
public void Adding_Items_Should_Fire_LogicalChildren_CollectionChanged() public void Adding_Items_Should_Fire_LogicalChildren_CollectionChanged()
{ {
@ -393,7 +373,7 @@ namespace Avalonia.Controls.UnitTests
} }
[Fact] [Fact]
public void Setting_Items_To_Null_Should_Fire_LogicalChildren_CollectionChanged() public void Clearing_Items_Should_Fire_LogicalChildren_CollectionChanged()
{ {
var target = new ItemsControl(); var target = new ItemsControl();
var child = new Control(); var child = new Control();
@ -406,25 +386,7 @@ namespace Avalonia.Controls.UnitTests
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) =>
called = e.Action == NotifyCollectionChangedAction.Remove; called = e.Action == NotifyCollectionChangedAction.Remove;
target.Items = null; target.Items.Clear();
Assert.True(called);
}
[Fact]
public void Changing_Items_Should_Fire_LogicalChildren_CollectionChanged()
{
var target = new ItemsControl();
var child = new Control();
var called = false;
target.Template = GetTemplate();
target.Items.Add(child);
target.ApplyTemplate();
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;
target.Items = new[] { "Foo" };
Assert.True(called); Assert.True(called);
} }
@ -437,16 +399,13 @@ namespace Avalonia.Controls.UnitTests
var called = false; var called = false;
target.Template = GetTemplate(); target.Template = GetTemplate();
target.Items = items; target.ItemsSource = items;
target.ApplyTemplate();
target.Presenter.ApplyTemplate();
((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => ((ILogical)target).LogicalChildren.CollectionChanged += (s, e) => called = true;
called = e.Action == NotifyCollectionChangedAction.Remove;
items.Remove("Bar"); items.Remove("Bar");
Assert.True(called); Assert.False(called);
} }
[Fact] [Fact]
@ -474,7 +433,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ItemsControl var target = new ItemsControl
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = GetTemplate(), Template = GetTemplate(),
}; };
@ -507,7 +466,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = new[] { 1, 2, 3 }, ItemsSource = new[] { 1, 2, 3 },
}; };
Assert.DoesNotContain(":empty", target.Classes); Assert.DoesNotContain(":empty", target.Classes);
@ -530,10 +489,10 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = new[] { 1, 2, 3 }, ItemsSource = new[] { 1, 2, 3 },
}; };
target.Items = new int[0]; target.ItemsSource = new int[0];
Assert.Contains(":empty", target.Classes); Assert.Contains(":empty", target.Classes);
} }
@ -544,7 +503,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = new[] { 1, 2, 3 }, ItemsSource = new[] { 1, 2, 3 },
}; };
Assert.Equal(3, target.ItemCount); Assert.Equal(3, target.ItemCount);
@ -558,7 +517,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
items.Add(4); items.Add(4);
@ -578,7 +537,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
items.Clear(); items.Clear();
@ -594,7 +553,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
items.Add(1); items.Add(1);
@ -603,14 +562,14 @@ namespace Avalonia.Controls.UnitTests
} }
[Fact] [Fact]
public void Single_Item_Class_Should_Be_Set_When_Items_Collection_Count_Increases_To_One() public void Single_Item_Class_Should_Be_Set_When_ItemsSource_Collection_Count_Increases_To_One()
{ {
var items = new ObservableCollection<int>() { }; var items = new ObservableCollection<int>() { };
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
items.Add(1); items.Add(1);
@ -626,7 +585,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
items.Clear(); items.Clear();
@ -642,7 +601,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl() var target = new ItemsControl()
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
items.Add(2); items.Add(2);
@ -669,7 +628,7 @@ namespace Avalonia.Controls.UnitTests
{ {
new FuncDataTemplate<Item>((x, __) => new Button { Content = x }) new FuncDataTemplate<Item>((x, __) => new Button { Content = x })
}, },
Items = items, ItemsSource = items,
}; };
target.ApplyTemplate(); target.ApplyTemplate();
@ -697,7 +656,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl var target = new ItemsControl
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
target.ApplyTemplate(); target.ApplyTemplate();
@ -721,7 +680,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl var target = new ItemsControl
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
var root = new TestRoot { Child = target }; var root = new TestRoot { Child = target };
@ -757,7 +716,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl var target = new ItemsControl
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = items, ItemsSource = items,
}; };
var root = new TestRoot { Child = target }; var root = new TestRoot { Child = target };
@ -785,7 +744,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ItemsControl var target = new ItemsControl
{ {
Template = GetTemplate(), Template = GetTemplate(),
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()),
}; };
@ -811,7 +770,7 @@ namespace Avalonia.Controls.UnitTests
DisplayMemberBinding = new Binding("Length") DisplayMemberBinding = new Binding("Length")
}; };
target.Items = new[] { "Foo" }; target.ItemsSource = new[] { "Foo" };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
@ -830,7 +789,7 @@ namespace Avalonia.Controls.UnitTests
DisplayMemberBinding = new Binding("Value") DisplayMemberBinding = new Binding("Value")
}; };
target.Items = new[] { new Item("Foo", "Bar") }; target.ItemsSource = new[] { new Item("Foo", "Bar") };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();

43
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -29,7 +29,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = new[] { "Foo" }, ItemsSource = new[] { "Foo" },
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()),
}; };
@ -81,7 +81,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);
@ -107,7 +107,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemContainerTheme = theme, ItemContainerTheme = theme,
}; };
@ -124,12 +124,11 @@ namespace Avalonia.Controls.UnitTests
{ {
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface)) using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{ {
var items = new[] { "Foo", "Bar", "Baz " };
var theme = new ControlTheme(typeof(ListBoxItem)); var theme = new ControlTheme(typeof(ListBoxItem));
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = new[] { new ListBoxItem() }, Items = { new ListBoxItem() },
ItemContainerTheme = theme, ItemContainerTheme = theme,
}; };
@ -149,7 +148,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
Prepare(target); Prepare(target);
@ -184,7 +183,7 @@ namespace Avalonia.Controls.UnitTests
{ {
new FuncDataTemplate<Item>((x, _) => new Button { Content = x }) new FuncDataTemplate<Item>((x, _) => new Button { Content = x })
}, },
Items = items, ItemsSource = items,
}; };
Prepare(target); Prepare(target);
@ -208,7 +207,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = Enumerable.Range(0, 20).Select(x => $"Item {x}").ToList(), ItemsSource = Enumerable.Range(0, 20).Select(x => $"Item {x}").ToList(),
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }),
SelectedIndex = 0, SelectedIndex = 0,
}; };
@ -236,7 +235,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = Enumerable.Range(0, 20).Select(x => $"Item {x}").ToList(), ItemsSource = Enumerable.Range(0, 20).Select(x => $"Item {x}").ToList(),
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectedIndex = 0, SelectedIndex = 0,
}; };
@ -258,7 +257,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectedIndex = 0, SelectedIndex = 0,
}; };
@ -272,7 +271,7 @@ namespace Avalonia.Controls.UnitTests
items.Remove("Item 2"); items.Remove("Item 2");
Layout(target); Layout(target);
var actual = target.Presenter.Panel.Children.Cast<ListBoxItem>().Select(x => (string)x.Content).ToList(); var actual = target.GetRealizedContainers().Cast<ListBoxItem>().Select(x => (string)x.Content).ToList();
Assert.Equal(items.OrderBy(x => x), actual.OrderBy(x => x)); Assert.Equal(items.OrderBy(x => x), actual.OrderBy(x => x));
} }
} }
@ -286,7 +285,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.Toggle, SelectionMode = SelectionMode.Toggle,
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }) ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 })
}; };
@ -318,7 +317,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }) ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 })
}; };
@ -364,7 +363,7 @@ namespace Avalonia.Controls.UnitTests
lm.ExecuteInitialLayoutPass(); lm.ExecuteInitialLayoutPass();
target.Items = items; target.ItemsSource = items;
lm.ExecuteLayoutPass(); lm.ExecuteLayoutPass();
@ -415,7 +414,7 @@ namespace Avalonia.Controls.UnitTests
Height = 100, Height = 100,
Width = 50, Width = 50,
ItemTemplate = new FuncDataTemplate<object>((c, _) => new Border() { Height = 10 }), ItemTemplate = new FuncDataTemplate<object>((c, _) => new Border() { Height = 10 }),
Items = items, ItemsSource = items,
}; };
wnd.Content = target; wnd.Content = target;
@ -450,7 +449,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }),
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
@ -497,7 +496,7 @@ namespace Avalonia.Controls.UnitTests
AutoScrollToSelectedItem = true, AutoScrollToSelectedItem = true,
Width = 50, Width = 50,
ItemTemplate = new FuncDataTemplate<object>((c, _) => new Border() { Height = 10 }), ItemTemplate = new FuncDataTemplate<object>((c, _) => new Border() { Height = 10 }),
Items = items, ItemsSource = items,
}; };
wnd.Content = target; wnd.Content = target;
@ -533,7 +532,7 @@ namespace Avalonia.Controls.UnitTests
{ {
var target = new ListBox var target = new ListBox
{ {
[!ListBox.ItemsProperty] = new Binding("Items"), [!ListBox.ItemsSourceProperty] = new Binding("Items"),
[!ListBox.SelectedItemsProperty] = new Binding("SelectedItems"), [!ListBox.SelectedItemsProperty] = new Binding("SelectedItems"),
}; };
@ -650,7 +649,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = new[] { "Foo" }, ItemsSource = new[] { "Foo" },
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas()),
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
@ -672,7 +671,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas { Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas { Height = 10 }),
}; };
@ -703,7 +702,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas { Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((_, __) => new Canvas { Height = 10 }),
AutoScrollToSelectedItem = true, AutoScrollToSelectedItem = true,
SelectedIndex = 1, SelectedIndex = 1,
@ -749,7 +748,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = ListBoxTemplate(), Template = ListBoxTemplate(),
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Height = 10 }),
WrapSelection = true WrapSelection = true
}; };

6
tests/Avalonia.Controls.UnitTests/ListBoxTests_Multiple.cs

@ -18,7 +18,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -41,7 +41,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -64,7 +64,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };

24
tests/Avalonia.Controls.UnitTests/ListBoxTests_Single.cs

@ -26,7 +26,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -45,7 +45,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -64,7 +64,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -86,7 +86,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target); ApplyTemplate(target);
@ -116,7 +116,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target); ApplyTemplate(target);
@ -134,7 +134,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
ApplyTemplate(target); ApplyTemplate(target);
@ -154,7 +154,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Single | SelectionMode.Toggle, SelectionMode = SelectionMode.Single | SelectionMode.Toggle,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
@ -174,7 +174,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Toggle, SelectionMode = SelectionMode.Toggle,
}; };
@ -196,7 +196,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.Toggle | SelectionMode.AlwaysSelected,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
@ -217,7 +217,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
SelectionMode = SelectionMode.Single | SelectionMode.Toggle, SelectionMode = SelectionMode.Single | SelectionMode.Toggle,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
@ -236,7 +236,7 @@ namespace Avalonia.Controls.UnitTests
var target = new ListBox var target = new ListBox
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -259,7 +259,7 @@ namespace Avalonia.Controls.UnitTests
{ {
Template = new FuncControlTemplate(CreateListBoxTemplate), Template = new FuncControlTemplate(CreateListBoxTemplate),
DataContext = viewModel, DataContext = viewModel,
Items = viewModel.Items ItemsSource = viewModel.Items
}; };
target.Bind(ListBox.SelectedItemProperty, target.Bind(ListBox.SelectedItemProperty,

10
tests/Avalonia.Controls.UnitTests/MenuItemTests.cs

@ -191,7 +191,7 @@ namespace Avalonia.Controls.UnitTests
return true; return true;
}); });
var target = new MenuItem(); var target = new MenuItem();
var contextMenu = new ContextMenu { Items = new AvaloniaList<MenuItem> { target } }; var contextMenu = new ContextMenu { Items = { target } };
var window = new Window { Content = new Panel { ContextMenu = contextMenu } }; var window = new Window { Content = new Panel { ContextMenu = contextMenu } };
window.ApplyStyling(); window.ApplyStyling();
window.ApplyTemplate(); window.ApplyTemplate();
@ -270,8 +270,8 @@ namespace Avalonia.Controls.UnitTests
return true; return true;
}); });
var target = new MenuItem(); var target = new MenuItem();
var parentMenuItem = new MenuItem { Items = new AvaloniaList<MenuItem> { target } }; var parentMenuItem = new MenuItem { Items = { target } };
var contextMenu = new ContextMenu { Items = new AvaloniaList<MenuItem> { parentMenuItem } }; var contextMenu = new ContextMenu { Items = { parentMenuItem } };
var window = new Window { Content = new Panel { ContextMenu = contextMenu } }; var window = new Window { Content = new Panel { ContextMenu = contextMenu } };
window.ApplyStyling(); window.ApplyStyling();
window.ApplyTemplate(); window.ApplyTemplate();
@ -317,12 +317,12 @@ namespace Avalonia.Controls.UnitTests
MenuItem childMenu2; MenuItem childMenu2;
var menu = new Menu var menu = new Menu
{ {
Items = new[] Items =
{ {
(topLevelMenu = new MenuItem (topLevelMenu = new MenuItem
{ {
Header = "Foo", Header = "Foo",
Items = new[] Items =
{ {
(childMenu1 = new MenuItem { Header = "Bar" }), (childMenu1 = new MenuItem { Header = "Bar" }),
(childMenu2 = new MenuItem { Header = "Baz" }), (childMenu2 = new MenuItem { Header = "Baz" }),

2
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests.cs

@ -114,7 +114,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
var panel = Assert.IsType<StackPanel>(target.Panel); var panel = Assert.IsType<StackPanel>(target.Panel);
var newItems = new[] { "qux", "quux", "corge" }; var newItems = new[] { "qux", "quux", "corge" };
itemsControl.Items = newItems; itemsControl.ItemsSource = newItems;
root.LayoutManager.ExecuteLayoutPass(); root.LayoutManager.ExecuteLayoutPass();
AssertContainers(panel, newItems); AssertContainers(panel, newItems);

4
tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs

@ -395,7 +395,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var item = new Border(); var item = new Border();
var root = PreparedWindow(target = new PopupItemsControl var root = PreparedWindow(target = new PopupItemsControl
{ {
Items = new[] { item }, Items = { item },
Template = new FuncControlTemplate<PopupItemsControl>(PopupItemsControlTemplate), Template = new FuncControlTemplate<PopupItemsControl>(PopupItemsControlTemplate),
}); ; }); ;
root.Show(); root.Show();
@ -490,7 +490,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var item = new Border(); var item = new Border();
var root = PreparedWindow(target = new PopupItemsControl var root = PreparedWindow(target = new PopupItemsControl
{ {
Items = new[] { item }, Items = { item },
Template = new FuncControlTemplate<PopupItemsControl>(PopupItemsControlTemplate), Template = new FuncControlTemplate<PopupItemsControl>(PopupItemsControlTemplate),
}); });
root.Show(); root.Show();

166
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests.cs

@ -43,7 +43,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -61,7 +61,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -82,7 +82,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -105,7 +105,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -127,7 +127,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox(); var target = new ListBox();
target.BeginInit(); target.BeginInit();
target.Items = items; target.ItemsSource = items;
target.Template = Template(); target.Template = Template();
target.EndInit(); target.EndInit();
@ -144,7 +144,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
}; };
var target = new ListBox(); var target = new ListBox();
target.Items = items; target.ItemsSource = items;
target.Template = Template(); target.Template = Template();
target.DataContext = new object(); target.DataContext = new object();
@ -163,7 +163,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox(); var target = new ListBox();
target.BeginInit(); target.BeginInit();
target.SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected; target.SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected;
target.Items = items; target.ItemsSource = items;
target.Template = Template(); target.Template = Template();
target.EndInit(); target.EndInit();
@ -184,7 +184,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
listBox.SelectedIndex = 1; listBox.SelectedIndex = 1;
var items = new AvaloniaList<string>(); var items = new AvaloniaList<string>();
listBox.Items = items; listBox.ItemsSource = items;
items.Add("A"); items.Add("A");
items.Add("B"); items.Add("B");
items.Add("C"); items.Add("C");
@ -202,7 +202,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var listBox = new ListBox var listBox = new ListBox
{ {
SelectionMode = SelectionMode.Single, SelectionMode = SelectionMode.Single,
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
SelectedIndex = 1 SelectedIndex = 1
}; };
@ -220,7 +220,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var listBox = new ListBox var listBox = new ListBox
{ {
SelectionMode = SelectionMode.Single, SelectionMode = SelectionMode.Single,
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
SelectedIndex = 2 SelectedIndex = 2
}; };
@ -240,7 +240,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var listBox = new ListBox var listBox = new ListBox
{ {
SelectionMode = SelectionMode.Single, SelectionMode = SelectionMode.Single,
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
SelectedItem = "bar" SelectedItem = "bar"
}; };
@ -259,7 +259,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var listBox = new ListBox var listBox = new ListBox
{ {
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
}; };
var selected = new[] { "foo", "bar" }; var selected = new[] { "foo", "bar" };
@ -282,7 +282,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var listBox = new ListBox var listBox = new ListBox
{ {
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
}; };
var selected = new[] { "foo", "bar" }; var selected = new[] { "foo", "bar" };
@ -308,7 +308,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.Single | SelectionMode.AlwaysSelected,
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
SelectedIndex = 1 SelectedIndex = 1
}; };
@ -331,7 +331,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -353,7 +353,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -376,7 +376,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -403,7 +403,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -430,7 +430,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -451,7 +451,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -487,7 +487,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -509,7 +509,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -519,7 +519,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.Equal(items[1], target.SelectedItem); Assert.Equal(items[1], target.SelectedItem);
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
target.Items = null; target.ItemsSource = null;
Assert.Null(target.SelectedItem); Assert.Null(target.SelectedItem);
Assert.Equal(-1, target.SelectedIndex); Assert.Equal(-1, target.SelectedIndex);
@ -536,7 +536,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -575,7 +575,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
@ -611,7 +611,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl(); var target = new SelectingItemsControl();
target.BeginInit(); target.BeginInit();
target.Items = items; target.ItemsSource = items;
target.Template = Template(); target.Template = Template();
target.EndInit(); target.EndInit();
@ -648,7 +648,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -684,7 +684,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -722,7 +722,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -749,7 +749,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -779,7 +779,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -807,7 +807,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -839,7 +839,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -868,7 +868,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedIndex = 1, SelectedIndex = 1,
}; };
@ -896,7 +896,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -932,7 +932,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -968,7 +968,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
@ -1004,7 +1004,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
@ -1041,7 +1041,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -1078,7 +1078,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
((ISupportInitialize)target).BeginInit(); ((ISupportInitialize)target).BeginInit();
target.SelectedIndex = 1; target.SelectedIndex = 1;
target.Items = items; target.ItemsSource = items;
((ISupportInitialize)target).EndInit(); ((ISupportInitialize)target).EndInit();
Prepare(target); Prepare(target);
@ -1096,7 +1096,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
((ISupportInitialize)target).BeginInit(); ((ISupportInitialize)target).BeginInit();
target.SelectedItem = "Bar"; target.SelectedItem = "Bar";
target.Items = items; target.ItemsSource = items;
((ISupportInitialize)target).EndInit(); ((ISupportInitialize)target).EndInit();
Prepare(target); Prepare(target);
@ -1127,7 +1127,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var itemsBinding = new Binding("Child.Items"); var itemsBinding = new Binding("Child.Items");
var selectedBinding = new Binding("Child.SelectedItem"); var selectedBinding = new Binding("Child.SelectedItem");
target.Bind(SelectingItemsControl.ItemsProperty, itemsBinding); target.Bind(SelectingItemsControl.ItemsSourceProperty, itemsBinding);
target.Bind(SelectingItemsControl.SelectedItemProperty, selectedBinding); target.Bind(SelectingItemsControl.SelectedItemProperty, selectedBinding);
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
@ -1163,13 +1163,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
var root = new SelectingItemsControl var root = new SelectingItemsControl
{ {
Template = Template(), Template = Template(),
Items = new Control[] ItemsSource = new Control[]
{ {
new Border(), new Border(),
nested = new ListBox nested = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
SelectedIndex = 1, SelectedIndex = 1,
} }
}, },
@ -1197,7 +1197,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target); Prepare(target);
@ -1221,7 +1221,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target); Prepare(target);
@ -1245,7 +1245,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
itemsMock.Object.AddRange(new[] { "Foo", "Bar", "Baz" }); itemsMock.Object.AddRange(new[] { "Foo", "Bar", "Baz" });
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = itemsMock.Object ItemsSource = itemsMock.Object
}; };
target.SelectedIndex = 1; target.SelectedIndex = 1;
@ -1268,7 +1268,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
target.BeginInit(); target.BeginInit();
root.Child = target; root.Child = target;
DelayedBinding.Add(target, ItemsControl.ItemsProperty, new Binding(nameof(RootWithItems.Items))); DelayedBinding.Add(target, ItemsControl.ItemsSourceProperty, new Binding(nameof(RootWithItems.Items)));
DelayedBinding.Add(target, ListBox.SelectedItemProperty, new Binding(nameof(RootWithItems.Selected))); DelayedBinding.Add(target, ListBox.SelectedItemProperty, new Binding(nameof(RootWithItems.Selected)));
target.EndInit(); target.EndInit();
root.EndInit(); root.EndInit();
@ -1299,7 +1299,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var itemsBinding = new Binding("Child.Items"); var itemsBinding = new Binding("Child.Items");
var selectedIndBinding = new Binding("Child.SelectedIndex"); var selectedIndBinding = new Binding("Child.SelectedIndex");
target.Bind(SelectingItemsControl.ItemsProperty, itemsBinding); target.Bind(SelectingItemsControl.ItemsSourceProperty, itemsBinding);
target.Bind(SelectingItemsControl.SelectedIndexProperty, selectedIndBinding); target.Bind(SelectingItemsControl.SelectedIndexProperty, selectedIndBinding);
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
@ -1318,7 +1318,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target); Prepare(target);
@ -1336,7 +1336,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
Prepare(target); Prepare(target);
@ -1359,7 +1359,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectedIndex = 1, SelectedIndex = 1,
}; };
@ -1384,7 +1384,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectedIndex = 1, SelectedIndex = 1,
}; };
@ -1405,14 +1405,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
var other = new ListBox var other = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
[!ListBox.SelectedIndexProperty] = other[!ListBox.SelectedIndexProperty], [!ListBox.SelectedIndexProperty] = other[!ListBox.SelectedIndexProperty],
}; };
@ -1434,14 +1434,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
var other = new ListBox var other = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
[!ListBox.SelectedItemProperty] = other[!ListBox.SelectedItemProperty], [!ListBox.SelectedItemProperty] = other[!ListBox.SelectedItemProperty],
}; };
@ -1468,7 +1468,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectedIndex = 1, SelectedIndex = 1,
}; };
@ -1493,7 +1493,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
}; };
var raised = false; var raised = false;
@ -1518,7 +1518,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
}; };
var raised = false; var raised = false;
@ -1540,7 +1540,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<string>((x, _) => ItemTemplate = new FuncDataTemplate<string>((x, _) =>
new TextBlock new TextBlock
{ {
@ -1582,7 +1582,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectedIndex = 2, SelectedIndex = 2,
}; };
@ -1614,7 +1614,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectedIndex = 2, SelectedIndex = 2,
}; };
@ -1645,7 +1645,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
AutoScrollToSelectedItem = false, AutoScrollToSelectedItem = false,
}; };
@ -1671,7 +1671,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
target.BeginInit(); target.BeginInit();
target.Template = Template(); target.Template = Template();
target.Items = new[] { "Foo", "Bar", "Baz" }; target.ItemsSource = new[] { "Foo", "Bar", "Baz" };
target.SelectedItems = selectedItems; target.SelectedItems = selectedItems;
target.SelectedItem = "Bar"; target.SelectedItem = "Bar";
target.EndInit(); target.EndInit();
@ -1691,7 +1691,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] Items =
{ {
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
@ -1713,7 +1713,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] Items =
{ {
new ListBoxItem(), new ListBoxItem(),
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
@ -1733,7 +1733,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] Items =
{ {
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
new ListBoxItem(), new ListBoxItem(),
@ -1753,7 +1753,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] Items =
{ {
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
@ -1776,7 +1776,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] Items =
{ {
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
new ListBoxItem { Focusable = false }, new ListBoxItem { Focusable = false },
@ -1800,7 +1800,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] Items =
{ {
new ListBoxItem(), new ListBoxItem(),
new ListBoxItem { IsEnabled = false }, new ListBoxItem { IsEnabled = false },
@ -1831,7 +1831,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
second second
}; };
target.Items = items; target.ItemsSource = items;
Prepare(target); Prepare(target);
@ -1878,7 +1878,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
[!ListBox.ItemsProperty] = new Binding("Items"), [!ListBox.ItemsSourceProperty] = new Binding("Items"),
[!ListBox.SelectedIndexProperty] = new Binding("SelectedIndex"), [!ListBox.SelectedIndexProperty] = new Binding("SelectedIndex"),
DataContext = vm, DataContext = vm,
}; };
@ -1906,7 +1906,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
[!ListBox.ItemsProperty] = new Binding("Items"), [!ListBox.ItemsSourceProperty] = new Binding("Items"),
[!ListBox.SelectedItemsProperty] = new Binding("SelectedItems"), [!ListBox.SelectedItemsProperty] = new Binding("SelectedItems"),
DataContext = vm, DataContext = vm,
}; };
@ -1926,7 +1926,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
using var app = Start(); using var app = Start();
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = new[] { "foo", "bar", "baz"}, ItemsSource = new[] { "foo", "bar", "baz"},
SelectedItem = "bar", SelectedItem = "bar",
}; };
@ -1935,7 +1935,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
Assert.Equal("bar", target.SelectedItem); Assert.Equal("bar", target.SelectedItem);
target.Items = new[] { "qux", "foo", "bar" }; target.ItemsSource = new[] { "qux", "foo", "bar" };
Assert.Equal(2, target.SelectedIndex); Assert.Equal(2, target.SelectedIndex);
Assert.Equal("bar", target.SelectedItem); Assert.Equal("bar", target.SelectedItem);
@ -1947,7 +1947,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
using var app = Start(); using var app = Start();
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
}; };
var raised = 0; var raised = 0;
@ -1976,7 +1976,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
using var app = Start(); using var app = Start();
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
}; };
var raised = 0; var raised = 0;
@ -2007,13 +2007,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
// Simulates problem with TabStrip and Carousel with bound SelectedIndex. // Simulates problem with TabStrip and Carousel with bound SelectedIndex.
var tabStrip = new TestSelector var tabStrip = new TestSelector
{ {
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
var carousel = new TestSelector var carousel = new TestSelector
{ {
Items = items, ItemsSource = items,
[!Carousel.SelectedIndexProperty] = tabStrip[!TabStrip.SelectedIndexProperty], [!Carousel.SelectedIndexProperty] = tabStrip[!TabStrip.SelectedIndexProperty],
}; };
@ -2048,13 +2048,13 @@ namespace Avalonia.Controls.UnitTests.Primitives
// Simulates problem with TabStrip and Carousel with bound SelectedItem. // Simulates problem with TabStrip and Carousel with bound SelectedItem.
var tabStrip = new TestSelector var tabStrip = new TestSelector
{ {
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.AlwaysSelected, SelectionMode = SelectionMode.AlwaysSelected,
}; };
var carousel = new TestSelector var carousel = new TestSelector
{ {
Items = items, ItemsSource = items,
[!Carousel.SelectedItemProperty] = tabStrip[!TabStrip.SelectedItemProperty], [!Carousel.SelectedItemProperty] = tabStrip[!TabStrip.SelectedItemProperty],
}; };
@ -2100,7 +2100,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new SelectingItemsControl var target = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
IsTextSearchEnabled = false IsTextSearchEnabled = false
}; };

12
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_AutoSelect.cs

@ -16,7 +16,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -32,7 +32,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = new AvaloniaList<string>(); var items = new AvaloniaList<string>();
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -50,7 +50,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = new ResetOnAdd(); var items = new ResetOnAdd();
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -68,7 +68,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -87,7 +87,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };
@ -106,7 +106,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = new AvaloniaList<string>(new[] { "foo", "bar" }); var items = new AvaloniaList<string>(new[] { "foo", "bar" });
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
}; };

231
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_Multiple.cs

@ -27,7 +27,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -42,7 +42,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -57,7 +57,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -75,7 +75,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
Template = Template(), Template = Template(),
}; };
@ -94,7 +94,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
// Issue #2565. // Issue #2565.
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
Template = Template(), Template = Template(),
}; };
@ -112,7 +112,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -129,7 +129,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -157,7 +157,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -179,7 +179,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -200,26 +200,23 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Adding_SelectedItems_Should_Set_Item_IsSelected() public void Adding_SelectedItems_Should_Set_Item_IsSelected()
{ {
var items = new[]
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
};
var target = new TestSelector var target = new TestSelector
{ {
Items = items, Items =
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
},
Template = Template(), Template = Template(),
}; };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
target.SelectedItems.Add(items[0]); target.SelectedItems.Add(target.Items[0]);
target.SelectedItems.Add(items[1]); target.SelectedItems.Add(target.Items[1]);
var foo = target.Presenter.Panel.Children[0];
var items = target.Items.Cast<ListBoxItem>().ToList();
Assert.True(items[0].IsSelected); Assert.True(items[0].IsSelected);
Assert.True(items[1].IsSelected); Assert.True(items[1].IsSelected);
Assert.False(items[2].IsSelected); Assert.False(items[2].IsSelected);
@ -228,23 +225,22 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Assigning_SelectedItems_Should_Set_Item_IsSelected() public void Assigning_SelectedItems_Should_Set_Item_IsSelected()
{ {
var items = new[]
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
};
var target = new TestSelector var target = new TestSelector
{ {
Items = items, Items =
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
},
Template = Template(), Template = Template(),
}; };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
target.SelectedItems = new AvaloniaList<object> { items[0], items[1] }; target.SelectedItems = new AvaloniaList<object> { target.Items[0], target.Items[1] };
var items = target.Items.Cast<ListBoxItem>().ToList();
Assert.True(items[0].IsSelected); Assert.True(items[0].IsSelected);
Assert.True(items[1].IsSelected); Assert.True(items[1].IsSelected);
Assert.False(items[2].IsSelected); Assert.False(items[2].IsSelected);
@ -253,25 +249,24 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Removing_SelectedItems_Should_Clear_Item_IsSelected() public void Removing_SelectedItems_Should_Clear_Item_IsSelected()
{ {
var items = new[]
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
};
var target = new TestSelector var target = new TestSelector
{ {
Items = items, Items =
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
},
Template = Template(), Template = Template(),
}; };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
target.SelectedItems.Add(items[0]); target.SelectedItems.Add(target.Items[0]);
target.SelectedItems.Add(items[1]); target.SelectedItems.Add(target.Items[1]);
target.SelectedItems.Remove(items[1]); target.SelectedItems.Remove(target.Items[1]);
var items = target.Items.Cast<ListBoxItem>().ToList();
Assert.True(items[0].IsSelected); Assert.True(items[0].IsSelected);
Assert.False(items[1].IsSelected); Assert.False(items[1].IsSelected);
} }
@ -279,25 +274,24 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Reassigning_SelectedItems_Should_Clear_Item_IsSelected() public void Reassigning_SelectedItems_Should_Clear_Item_IsSelected()
{ {
var items = new[]
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
};
var target = new TestSelector var target = new TestSelector
{ {
Items = items, Items =
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
},
Template = Template(), Template = Template(),
}; };
target.ApplyTemplate(); target.ApplyTemplate();
target.SelectedItems.Add(items[0]); target.SelectedItems.Add(target.Items[0]);
target.SelectedItems.Add(items[1]); target.SelectedItems.Add(target.Items[1]);
target.SelectedItems = new AvaloniaList<object> { items[0], items[1] }; target.SelectedItems = new AvaloniaList<object> { target.Items[0], target.Items[1] };
var items = target.Items.Cast<ListBoxItem>().ToList();
Assert.False(items[0].IsSelected); Assert.False(items[0].IsSelected);
Assert.False(items[1].IsSelected); Assert.False(items[1].IsSelected);
} }
@ -307,7 +301,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
Template = Template(), Template = Template(),
}; };
@ -329,7 +323,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] ItemsSource = new[]
{ {
"foo", "foo",
"bar", "bar",
@ -353,7 +347,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] ItemsSource = new[]
{ {
"foo", "foo",
"bar", "bar",
@ -378,7 +372,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] ItemsSource = new[]
{ {
"foo", "foo",
"bar", "bar",
@ -404,7 +398,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz", "qux" }, ItemsSource = new[] { "foo", "bar", "baz", "qux" },
Template = Template(), Template = Template(),
SelectedIndex = 0, SelectedIndex = 0,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
@ -427,7 +421,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz", "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz", "foo", "bar", "baz" },
Template = Template(), Template = Template(),
SelectedIndex = 0, SelectedIndex = 0,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
@ -450,7 +444,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
Template = Template(), Template = Template(),
}; };
@ -471,7 +465,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
Template = Template(), Template = Template(),
}; };
@ -536,8 +530,8 @@ namespace Avalonia.Controls.UnitTests.Primitives
Mode = BindingMode.OneWay, Mode = BindingMode.OneWay,
}; };
// Bind Items and SelectedItems to the VM. // Bind ItemsSource and SelectedItems to the VM.
target.Bind(TestSelector.ItemsProperty, itemsBinding); target.Bind(TestSelector.ItemsSourceProperty, itemsBinding);
target.Bind(TestSelector.SelectedItemsProperty, selectedItemsBinding); target.Bind(TestSelector.SelectedItemsProperty, selectedItemsBinding);
// Set DataContext and SelectedIndex // Set DataContext and SelectedIndex
@ -576,8 +570,8 @@ namespace Avalonia.Controls.UnitTests.Primitives
Mode = BindingMode.OneWay, Mode = BindingMode.OneWay,
}; };
// Bind Items and Selection to the VM. // Bind ItemsSource and Selection to the VM.
target.Bind(TestSelector.ItemsProperty, itemsBinding); target.Bind(TestSelector.ItemsSourceProperty, itemsBinding);
target.Bind(TestSelector.SelectionProperty, selectionBinding); target.Bind(TestSelector.SelectionProperty, selectionBinding);
// Set DataContext and SelectedIndex // Set DataContext and SelectedIndex
@ -610,9 +604,9 @@ namespace Avalonia.Controls.UnitTests.Primitives
}; };
var itemsBinding = new Binding { Path = "Items" }; var itemsBinding = new Binding { Path = "Items" };
target.Bind(TestSelector.ItemsProperty, itemsBinding); target.Bind(TestSelector.ItemsSourceProperty, itemsBinding);
Assert.Same(data.Items, target.Items); Assert.Same(data.Items, target.ItemsSource);
target.SelectedItems.Add("bar"); target.SelectedItems.Add("bar");
target.DataContext = null; target.DataContext = null;
@ -629,7 +623,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
DataContext = items, DataContext = items,
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
}; };
var called = false; var called = false;
@ -653,7 +647,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedItem = "bar", SelectedItem = "bar",
}; };
@ -679,7 +673,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedItem = "bar", SelectedItem = "bar",
}; };
@ -708,7 +702,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -733,7 +727,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -791,7 +785,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -825,7 +819,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -856,7 +850,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -884,7 +878,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -912,7 +906,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -940,7 +934,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Qux" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Qux" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -992,7 +986,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -1026,7 +1020,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1045,7 +1039,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1059,7 +1053,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
target.SelectAll(); target.SelectAll();
Assert.NotNull(receivedArgs); Assert.NotNull(receivedArgs);
Assert.Equal(target.Items, receivedArgs.AddedItems); Assert.Equal(target.ItemsSource, receivedArgs.AddedItems);
Assert.Empty(receivedArgs.RemovedItems); Assert.Empty(receivedArgs.RemovedItems);
} }
@ -1069,7 +1063,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
SelectedIndex = 0, SelectedIndex = 0,
}; };
@ -1089,7 +1083,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" },
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1113,7 +1107,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -1145,7 +1139,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1178,7 +1172,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -1209,7 +1203,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = items, ItemsSource = items,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
Height = 100, Height = 100,
@ -1232,7 +1226,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
@ -1262,7 +1256,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
@ -1290,7 +1284,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
@ -1315,27 +1309,25 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Adding_Selected_ItemContainers_Should_Update_Selection() public void Adding_Selected_ItemContainers_Should_Update_Selection()
{ {
var items = new AvaloniaList<ItemContainer>(new[]
{
new ItemContainer(),
new ItemContainer(),
});
var target = new TestSelector var target = new TestSelector
{ {
Items = items, Items =
{
new ItemContainer(),
new ItemContainer(),
},
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Template = Template(), Template = Template(),
}; };
target.ApplyTemplate(); target.ApplyTemplate();
target.Presenter.ApplyTemplate(); target.Presenter.ApplyTemplate();
items.Add(new ItemContainer { IsSelected = true }); target.Items.Add(new ItemContainer { IsSelected = true });
items.Add(new ItemContainer { IsSelected = true }); target.Items.Add(new ItemContainer { IsSelected = true });
Assert.Equal(2, target.SelectedIndex); Assert.Equal(2, target.SelectedIndex);
Assert.Equal(items[2], target.SelectedItem); Assert.Equal(target.Items[2], target.SelectedItem);
Assert.Equal(new[] { items[2], items[3] }, target.SelectedItems); Assert.Equal(new[] { target.Items[2], target.Items[3] }, target.SelectedItems);
} }
[Fact] [Fact]
@ -1346,7 +1338,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
@ -1373,7 +1365,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new ListBox var target = new ListBox
{ {
Template = Template(), Template = Template(),
Items = new[] { "Foo", "Bar", "Baz" }, ItemsSource = new[] { "Foo", "Bar", "Baz" },
ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }), ItemTemplate = new FuncDataTemplate<string>((x, _) => new TextBlock { Width = 20, Height = 10 }),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Width = 100, Width = 100,
@ -1397,7 +1389,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -1412,7 +1404,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -1429,7 +1421,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -1442,14 +1434,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
var selection = new SelectionModel<string>(); var selection = new SelectionModel<string>();
target.Selection = selection; target.Selection = selection;
Assert.Same(target.Items, selection.Source); Assert.Same(target.ItemsSource, selection.Source);
} }
[Fact] [Fact]
@ -1457,7 +1449,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -1478,7 +1470,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar", "baz" }, ItemsSource = new[] { "foo", "bar", "baz" },
Template = Template(), Template = Template(),
}; };
@ -1499,7 +1491,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
{ {
var target = new TestSelector var target = new TestSelector
{ {
Items = new[] { "foo", "bar" }, ItemsSource = new[] { "foo", "bar" },
Template = Template(), Template = Template(),
}; };
@ -1514,16 +1506,14 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void Assigning_Selection_Should_Set_Item_IsSelected() public void Assigning_Selection_Should_Set_Item_IsSelected()
{ {
var items = new[]
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
};
var target = new TestSelector var target = new TestSelector
{ {
Items = items, Items =
{
new ListBoxItem(),
new ListBoxItem(),
new ListBoxItem(),
},
Template = Template(), Template = Template(),
}; };
@ -1534,6 +1524,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
selection.SelectRange(0, 1); selection.SelectRange(0, 1);
target.Selection = selection; target.Selection = selection;
var items = target.Items.Cast<ListBoxItem>().ToList();
Assert.True(items[0].IsSelected); Assert.True(items[0].IsSelected);
Assert.True(items[1].IsSelected); Assert.True(items[1].IsSelected);
Assert.False(items[2].IsSelected); Assert.False(items[2].IsSelected);
@ -1546,7 +1537,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var target = new TestSelector var target = new TestSelector
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedItem = "bar", SelectedItem = "bar",
}; };

26
tests/Avalonia.Controls.UnitTests/Primitives/SelectingItemsControlTests_SelectedValue.cs

@ -21,7 +21,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
Template = Template() Template = Template()
}; };
@ -37,7 +37,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
Template = Template() Template = Template()
}; };
@ -53,7 +53,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new ListBox var sic = new ListBox
{ {
Items = items, ItemsSource = items,
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
Template = Template() Template = Template()
}; };
@ -78,7 +78,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
Template = Template() Template = Template()
}; };
@ -99,7 +99,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
Template = Template() Template = Template()
}; };
@ -120,7 +120,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
Template = Template() Template = Template()
}; };
@ -143,7 +143,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template() Template = Template()
}; };
@ -158,7 +158,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
SelectedValue = "Item2" SelectedValue = "Item2"
@ -176,7 +176,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
SelectedValue = "Item2" SelectedValue = "Item2"
@ -197,7 +197,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
SelectedValue = "Item2" SelectedValue = "Item2"
@ -205,7 +205,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
Prepare(sic); Prepare(sic);
sic.Items = new List<TestClass> sic.ItemsSource = new List<TestClass>
{ {
new TestClass("NewItem", string.Empty) new TestClass("NewItem", string.Empty)
}; };
@ -224,7 +224,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
}; };
@ -250,7 +250,7 @@ namespace Avalonia.Controls.UnitTests.Primitives
var items = TestClass.GetItems(); var items = TestClass.GetItems();
var sic = new SelectingItemsControl var sic = new SelectingItemsControl
{ {
Items = items, ItemsSource = items,
Template = Template(), Template = Template(),
SelectedValueBinding = new Binding("Name"), SelectedValueBinding = new Binding("Name"),
SelectedValue = "Item2" SelectedValue = "Item2"

94
tests/Avalonia.Controls.UnitTests/Primitives/TabStripTests.cs

@ -14,90 +14,84 @@ namespace Avalonia.Controls.UnitTests.Primitives
[Fact] [Fact]
public void First_Tab_Should_Be_Selected_By_Default() public void First_Tab_Should_Be_Selected_By_Default()
{ {
var items = new[]
{
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
};
var target = new TabStrip var target = new TabStrip
{ {
Template = new FuncControlTemplate<TabStrip>(CreateTabStripTemplate), Template = new FuncControlTemplate<TabStrip>(CreateTabStripTemplate),
Items = items, Items =
{
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
}
}; };
target.ApplyTemplate(); target.ApplyTemplate();
Assert.Equal(0, target.SelectedIndex); Assert.Equal(0, target.SelectedIndex);
Assert.Same(items[0], target.SelectedItem); Assert.Same(target.Items[0], target.SelectedItem);
} }
[Fact] [Fact]
public void Setting_SelectedItem_Should_Set_Selection() public void Setting_SelectedItem_Should_Set_Selection()
{ {
var items = new[]
{
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
};
var target = new TabStrip var target = new TabStrip
{ {
Template = new FuncControlTemplate<TabStrip>(CreateTabStripTemplate), Template = new FuncControlTemplate<TabStrip>(CreateTabStripTemplate),
Items = items, Items =
SelectedItem = items[1], {
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
},
}; };
target.SelectedItem = target.Items[1];
target.ApplyTemplate(); target.ApplyTemplate();
Assert.Equal(1, target.SelectedIndex); Assert.Equal(1, target.SelectedIndex);
Assert.Same(items[1], target.SelectedItem); Assert.Same(target.Items[1], target.SelectedItem);
} }
[Fact] [Fact]
public void Removing_Selected_Should_Select_First() public void Removing_Selected_Should_Select_First()
{ {
var items = new ObservableCollection<TabItem>()
{
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
new TabItem
{
Name = "3rd"
},
};
var target = new TabStrip var target = new TabStrip
{ {
Template = new FuncControlTemplate<TabStrip>(CreateTabStripTemplate), Template = new FuncControlTemplate<TabStrip>(CreateTabStripTemplate),
Items = items Items =
{
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
new TabItem
{
Name = "3rd"
},
}
}; };
target.ApplyTemplate(); target.ApplyTemplate();
target.SelectedItem = items[1]; target.SelectedItem = target.Items[1];
Assert.Same(items[1], target.SelectedItem); Assert.Same(target.Items[1], target.SelectedItem);
items.RemoveAt(1); target.Items.RemoveAt(1);
Assert.Equal(0, target.SelectedIndex); Assert.Equal(0, target.SelectedIndex);
Assert.Same(items[0], target.SelectedItem); Assert.Same(target.Items[0], target.SelectedItem);
Assert.Same("first", ((TabItem)target.SelectedItem).Name); Assert.Same("first", ((TabItem)target.SelectedItem).Name);
} }

154
tests/Avalonia.Controls.UnitTests/TabControlTests.cs

@ -24,7 +24,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = new[] Items =
{ {
(selected = new TabItem (selected = new TabItem
{ {
@ -48,21 +48,17 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void Pre_Selecting_TabItem_Should_Set_SelectedContent_After_It_Was_Added() public void Pre_Selecting_TabItem_Should_Set_SelectedContent_After_It_Was_Added()
{ {
const string secondContent = "Second";
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items =
{
new TabItem { Header = "First"},
new TabItem { Header = "Second", Content = secondContent, IsSelected = true }
},
}; };
const string secondContent = "Second";
var items = new AvaloniaList<object>
{
new TabItem { Header = "First"},
new TabItem { Header = "Second", Content = secondContent, IsSelected = true }
};
target.Items = items;
ApplyTemplate(target); ApplyTemplate(target);
Assert.Equal(secondContent, target.SelectedContent); Assert.Equal(secondContent, target.SelectedContent);
@ -74,7 +70,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = Items =
{ {
new TabItem new TabItem
{ {
@ -87,89 +83,89 @@ namespace Avalonia.Controls.UnitTests
} }
}; };
Assert.Equal(target.Items.Cast<ILogical>(), target.GetLogicalChildren()); Assert.Equal(target.Items, target.GetLogicalChildren().ToList());
target.ApplyTemplate(); target.ApplyTemplate();
Assert.Equal(target.Items.Cast<ILogical>(), target.GetLogicalChildren()); Assert.Equal(target.Items, target.GetLogicalChildren().ToList());
} }
[Fact] [Fact]
public void Removal_Should_Set_First_Tab() public void Removal_Should_Set_First_Tab()
{ {
var collection = new ObservableCollection<TabItem>()
{
new TabItem
{
Name = "first",
Content = "foo",
},
new TabItem
{
Name = "second",
Content = "bar",
},
new TabItem
{
Name = "3rd",
Content = "barf",
},
};
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = collection, Items =
{
new TabItem
{
Name = "first",
Content = "foo",
},
new TabItem
{
Name = "second",
Content = "bar",
},
new TabItem
{
Name = "3rd",
Content = "barf",
},
}
}; };
Prepare(target); Prepare(target);
target.SelectedItem = collection[1]; target.SelectedItem = target.Items[1];
Assert.Same(collection[1], target.SelectedItem); var item = Assert.IsType<TabItem>(target.Items[1]);
Assert.Equal(collection[1].Content, target.SelectedContent); Assert.Same(item, target.SelectedItem);
Assert.Equal(item.Content, target.SelectedContent);
collection.RemoveAt(1); target.Items.RemoveAt(1);
Assert.Same(collection[0], target.SelectedItem); item = Assert.IsType<TabItem>(target.Items[0]);
Assert.Equal(collection[0].Content, target.SelectedContent); Assert.Same(item, target.SelectedItem);
Assert.Equal(item.Content, target.SelectedContent);
} }
[Fact] [Fact]
public void Removal_Should_Set_New_Item0_When_Item0_Selected() public void Removal_Should_Set_New_Item0_When_Item0_Selected()
{ {
var collection = new ObservableCollection<TabItem>()
{
new TabItem
{
Name = "first",
Content = "foo",
},
new TabItem
{
Name = "second",
Content = "bar",
},
new TabItem
{
Name = "3rd",
Content = "barf",
},
};
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = collection, Items =
{
new TabItem
{
Name = "first",
Content = "foo",
},
new TabItem
{
Name = "second",
Content = "bar",
},
new TabItem
{
Name = "3rd",
Content = "barf",
},
}
}; };
Prepare(target); Prepare(target);
target.SelectedItem = collection[0]; target.SelectedItem = target.Items[0];
Assert.Same(collection[0], target.SelectedItem); var item = Assert.IsType<TabItem>(target.Items[0]);
Assert.Equal(collection[0].Content, target.SelectedContent); Assert.Same(item, target.SelectedItem);
Assert.Equal(item.Content, target.SelectedContent);
collection.RemoveAt(0); target.Items.RemoveAt(0);
Assert.Same(collection[0], target.SelectedItem); item = Assert.IsType<TabItem>(target.Items[0]);
Assert.Equal(collection[0].Content, target.SelectedContent); Assert.Same(item, target.SelectedItem);
Assert.Equal(item.Content, target.SelectedContent);
} }
[Fact] [Fact]
@ -187,7 +183,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = collection, ItemsSource = collection,
}; };
Prepare(target); Prepare(target);
@ -269,7 +265,7 @@ namespace Avalonia.Controls.UnitTests
{ {
new FuncDataTemplate<Item>((x, __) => new Button { Content = x }) new FuncDataTemplate<Item>((x, __) => new Button { Content = x })
}, },
Items = items, ItemsSource = items,
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -311,16 +307,14 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void Non_IHeadered_Control_Items_Should_Be_Ignored() public void Non_IHeadered_Control_Items_Should_Be_Ignored()
{ {
var items = new[]
{
new TextBlock { Text = "foo" },
new TextBlock { Text = "bar" },
};
var target = new TabControl var target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = items, Items =
{
new TextBlock { Text = "foo" },
new TextBlock { Text = "bar" },
},
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -341,7 +335,7 @@ namespace Avalonia.Controls.UnitTests
TabControl target = new TabControl TabControl target = new TabControl
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
Items = new[] Items =
{ {
new TabItem { Header = "Foo" }, new TabItem { Header = "Foo" },
new TabItem { Header = "Foo", Content = new Decorator() }, new TabItem { Header = "Foo", Content = new Decorator() },
@ -366,7 +360,7 @@ namespace Avalonia.Controls.UnitTests
Template = TabControlTemplate(), Template = TabControlTemplate(),
ContentTemplate = new FuncDataTemplate<string>((x, _) => ContentTemplate = new FuncDataTemplate<string>((x, _) =>
new TextBlock { Tag = "bar", Text = x }), new TextBlock { Tag = "bar", Text = x }),
Items = new[] { "Foo" }, ItemsSource = new[] { "Foo" },
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -390,7 +384,7 @@ namespace Avalonia.Controls.UnitTests
{ {
Template = TabControlTemplate(), Template = TabControlTemplate(),
DataContext = dataContext, DataContext = dataContext,
Items = new AvaloniaList<object> { tabItem } Items = { tabItem }
}; };
ApplyTemplate(target); ApplyTemplate(target);
@ -407,7 +401,7 @@ namespace Avalonia.Controls.UnitTests
<Window xmlns='https://github.com/avaloniaui' <Window xmlns='https://github.com/avaloniaui'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'> xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Xaml;assembly=Avalonia.Markup.Xaml.UnitTests'>
<TabControl Name='tabs' Items='{Binding Tabs}'/> <TabControl Name='tabs' ItemsSource='{Binding Tabs}'/>
</Window>"; </Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var tabControl = window.FindControl<TabControl>("tabs"); var tabControl = window.FindControl<TabControl>("tabs");
@ -415,7 +409,7 @@ namespace Avalonia.Controls.UnitTests
tabControl.DataContext = new { Tabs = new List<string>() }; tabControl.DataContext = new { Tabs = new List<string>() };
window.ApplyTemplate(); window.ApplyTemplate();
Assert.Equal(0, tabControl.Items.Count()); Assert.Equal(0, tabControl.ItemsSource.Count());
} }
} }

116
tests/Avalonia.Controls.UnitTests/TreeViewTests.cs

@ -31,7 +31,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = CreateTestTreeData(), ItemsSource = CreateTestTreeData(),
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -54,7 +54,7 @@ namespace Avalonia.Controls.UnitTests
Child = target = new TreeView Child = target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = CreateTestTreeData(), ItemsSource = CreateTestTreeData(),
ItemTemplate = new FuncTreeDataTemplate<Node>( ItemTemplate = new FuncTreeDataTemplate<Node>(
(_, __) => new Canvas(), (_, __) => new Canvas(),
x => x.Children), x => x.Children),
@ -82,7 +82,7 @@ namespace Avalonia.Controls.UnitTests
Child = target = new TreeView Child = target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = CreateTestTreeData(), ItemsSource = CreateTestTreeData(),
ItemContainerTheme = theme, ItemContainerTheme = theme,
ItemTemplate = new FuncTreeDataTemplate<Node>( ItemTemplate = new FuncTreeDataTemplate<Node>(
(_, __) => new Canvas(), (_, __) => new Canvas(),
@ -112,7 +112,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = CreateTestTreeData(), ItemsSource = CreateTestTreeData(),
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -131,7 +131,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = CreateTestTreeData(), ItemsSource = CreateTestTreeData(),
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -151,7 +151,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
// For TreeViewItem to find its parent TreeView, OnAttachedToLogicalTree needs // For TreeViewItem to find its parent TreeView, OnAttachedToLogicalTree needs
@ -181,7 +181,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -212,7 +212,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree ItemsSource = tree
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -247,7 +247,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree ItemsSource = tree
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -287,7 +287,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -330,7 +330,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -367,7 +367,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -404,7 +404,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -455,7 +455,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -488,7 +488,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -521,7 +521,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -554,7 +554,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -591,7 +591,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -649,7 +649,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -686,7 +686,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -744,7 +744,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -781,7 +781,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -839,7 +839,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -876,7 +876,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -934,7 +934,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -985,7 +985,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1036,7 +1036,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1066,7 +1066,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1105,7 +1105,7 @@ namespace Avalonia.Controls.UnitTests
DataContext = dataContext DataContext = dataContext
}; };
target.Bind(TreeView.ItemsProperty, new Binding("Items")); target.Bind(TreeView.ItemsSourceProperty, new Binding("Items"));
target.Bind(TreeView.SelectedItemProperty, new Binding("SelectedItem")); target.Bind(TreeView.SelectedItemProperty, new Binding("SelectedItem"));
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1137,7 +1137,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = new[] { "Foo", "Bar", "Baz " }, ItemsSource = new[] { "Foo", "Bar", "Baz " },
}; };
ApplyTemplates(target); ApplyTemplates(target);
@ -1171,7 +1171,7 @@ namespace Avalonia.Controls.UnitTests
{ {
new FuncDataTemplate<Node>((x, _) => new Button { Content = x }) new FuncDataTemplate<Node>((x, _) => new Button { Content = x })
}, },
Items = items, ItemsSource = items,
}; };
ApplyTemplates(target); ApplyTemplates(target);
@ -1189,15 +1189,13 @@ namespace Avalonia.Controls.UnitTests
[Fact] [Fact]
public void Control_Item_Should_Not_Be_NameScope() public void Control_Item_Should_Not_Be_NameScope()
{ {
var items = new object[]
{
new TreeViewItem(),
};
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = items, Items =
{
new TreeViewItem(),
}
}; };
target.ApplyTemplate(); target.ApplyTemplate();
@ -1215,7 +1213,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = data, ItemsSource = data,
}; };
var root = new TestRoot(target); var root = new TestRoot(target);
@ -1256,7 +1254,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = data, ItemsSource = data,
}; };
var button = new Button(); var button = new Button();
@ -1302,7 +1300,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = data, ItemsSource = data,
SelectedItem = selectedNode SelectedItem = selectedNode
}; };
@ -1341,7 +1339,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -1379,7 +1377,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -1426,7 +1424,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple SelectionMode = SelectionMode.Multiple
}; };
@ -1473,7 +1471,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object); AvaloniaLocator.CurrentMutable.Bind<PlatformHotkeyConfiguration>().ToConstant(new Mock<PlatformHotkeyConfiguration>().Object);
@ -1503,7 +1501,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1542,7 +1540,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1575,7 +1573,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
}; };
@ -1606,7 +1604,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1630,7 +1628,7 @@ namespace Avalonia.Controls.UnitTests
var target = new DerivedTreeView var target = new DerivedTreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1655,7 +1653,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var visualRoot = new TestRoot(); var visualRoot = new TestRoot();
@ -1688,11 +1686,11 @@ namespace Avalonia.Controls.UnitTests
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
SelectionMode = SelectionMode.Multiple, SelectionMode = SelectionMode.Multiple,
Items = new List<Node> ItemsSource = new List<Node>
{ {
new Node { Value = "Root1", }, new Node { Value = "Root1", },
new Node { Value = "Root2", }, new Node { Value = "Root2", },
}, },
}; };
var visualRoot = new TestRoot var visualRoot = new TestRoot
@ -1726,7 +1724,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var root = new TestRoot(); var root = new TestRoot();
@ -1760,7 +1758,7 @@ namespace Avalonia.Controls.UnitTests
var target = new TreeView var target = new TreeView
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
var root = new TestRoot(); var root = new TestRoot();
@ -1788,7 +1786,7 @@ namespace Avalonia.Controls.UnitTests
var target = new DerivedTreeViewWithDerivedTreeViewItems var target = new DerivedTreeViewWithDerivedTreeViewItems
{ {
Template = CreateTreeViewTemplate(), Template = CreateTreeViewTemplate(),
Items = tree, ItemsSource = tree,
}; };
ApplyTemplates(target); ApplyTemplates(target);
@ -1825,7 +1823,7 @@ namespace Avalonia.Controls.UnitTests
foreach (var index in indexes) foreach (var index in indexes)
{ {
var item = ((IList)c.Items)[index]; var item = c.ItemsView[index];
c = (ItemsControl)target.TreeContainerFromItem(item); c = (ItemsControl)target.TreeContainerFromItem(item);
} }

4
tests/Avalonia.Controls.UnitTests/Utils/HotKeyManagerTests.cs

@ -263,7 +263,7 @@ namespace Avalonia.Controls.UnitTests.Utils
}; };
var rootMenu = new Menu(); var rootMenu = new Menu();
rootMenu.Items = new[] { menuitem }; rootMenu.Items.Add(menuitem);
root.Content = rootMenu; root.Content = rootMenu;
return menuitem; return menuitem;
@ -288,7 +288,7 @@ namespace Avalonia.Controls.UnitTests.Utils
}; };
var rootMenu = new Menu(); var rootMenu = new Menu();
rootMenu.Items = new[] { menuitem }; rootMenu.Items.Add(menuitem);
root.Content = rootMenu; root.Content = rootMenu;
return menuitem; return menuitem;

2
tests/Avalonia.Controls.UnitTests/VirtualizingStackPanelTests.cs

@ -50,7 +50,7 @@ namespace Avalonia.Controls.UnitTests
Assert.Empty(itemsControl.GetRealizedContainers()); Assert.Empty(itemsControl.GetRealizedContainers());
itemsControl.Items = new[] { "foo", "bar" }; itemsControl.ItemsSource = new[] { "foo", "bar" };
Layout(target); Layout(target);
AssertRealizedItems(target, itemsControl, 0, 2); AssertRealizedItems(target, itemsControl, 0, 2);

14
tests/Avalonia.LeakTests/ControlTests.cs

@ -353,7 +353,7 @@ namespace Avalonia.LeakTests
(x, _) => new TextBlock { Text = x.Name }, (x, _) => new TextBlock { Text = x.Name },
x => x.Children) x => x.Children)
}, },
Items = nodes ItemsSource = nodes
} }
}; };
@ -428,7 +428,7 @@ namespace Avalonia.LeakTests
{ {
Content = new TabControl Content = new TabControl
{ {
Items = new[] { new TabItem() } ItemsSource = new[] { new TabItem() }
} }
}; };
@ -440,7 +440,7 @@ namespace Avalonia.LeakTests
Assert.IsType<TabItem>(tabControl.Presenter.Panel.Children[0]); Assert.IsType<TabItem>(tabControl.Presenter.Panel.Children[0]);
// Clear the items and ensure the TabItem is removed. // Clear the items and ensure the TabItem is removed.
tabControl.Items = null; tabControl.ItemsSource = null;
window.LayoutManager.ExecuteLayoutPass(); window.LayoutManager.ExecuteLayoutPass();
Assert.Empty(tabControl.Presenter.Panel.Children); Assert.Empty(tabControl.Presenter.Panel.Children);
@ -545,7 +545,7 @@ namespace Avalonia.LeakTests
{ {
var contextMenu = new ContextMenu var contextMenu = new ContextMenu
{ {
Items = new[] Items =
{ {
new MenuItem { Header = "Foo" }, new MenuItem { Header = "Foo" },
new MenuItem { Header = "Foo" }, new MenuItem { Header = "Foo" },
@ -594,7 +594,7 @@ namespace Avalonia.LeakTests
{ {
var contextMenu = new ContextMenu var contextMenu = new ContextMenu
{ {
Items = new[] Items =
{ {
new MenuItem { Header = "Foo" }, new MenuItem { Header = "Foo" },
new MenuItem { Header = "Foo" }, new MenuItem { Header = "Foo" },
@ -740,7 +740,7 @@ namespace Avalonia.LeakTests
}), }),
(lb = new ListBox (lb = new ListBox
{ {
Items = items, ItemsSource = items,
ItemTemplate = new FuncDataTemplate<int>((_, _) => ItemTemplate = new FuncDataTemplate<int>((_, _) =>
new Canvas new Canvas
{ {
@ -858,7 +858,7 @@ namespace Avalonia.LeakTests
// Add the listbox and render it // Add the listbox and render it
tl.Content = listBox; tl.Content = listBox;
lm.ExecuteInitialLayoutPass(); lm.ExecuteInitialLayoutPass();
listBox.Items = keyGestures; listBox.ItemsSource = keyGestures;
lm.ExecuteLayoutPass(); lm.ExecuteLayoutPass();
// Let the button detach when clearing the source items // Let the button detach when clearing the source items

8
tests/Avalonia.Markup.UnitTests/Data/MultiBindingTests.cs

@ -173,11 +173,11 @@ namespace Avalonia.Markup.UnitTests.Data
}, },
}; };
target.Bind(ItemsControl.ItemsProperty, binding); target.Bind(ItemsControl.ItemsSourceProperty, binding);
Assert.Equal(target.ItemCount, 3); Assert.Equal(target.ItemCount, 3);
Assert.Equal(target.Items.ElementAt(0), source.A); Assert.Equal(target.ItemsView[0], source.A);
Assert.Equal(target.Items.ElementAt(1), source.B); Assert.Equal(target.ItemsView[1], source.B);
Assert.Equal(target.Items.ElementAt(2), source.C); Assert.Equal(target.ItemsView[2], source.C);
} }
private class ConcatConverter : IMultiValueConverter private class ConcatConverter : IMultiValueConverter

8
tests/Avalonia.Markup.Xaml.UnitTests/MarkupExtensions/CompiledBindingExtensionTests.cs

@ -122,7 +122,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests' xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests'
x:DataType='local:TestDataContext'> x:DataType='local:TestDataContext'>
<ItemsControl Name='itemsControl' Items='{CompiledBinding Path=ListProperty}'> <ItemsControl Name='itemsControl' ItemsSource='{CompiledBinding Path=ListProperty}'>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock /> <TextBlock />
@ -143,7 +143,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
window.DataContext = dataContext; window.DataContext = dataContext;
Assert.Equal(dataContext.ListProperty, textBlock.Items); Assert.Equal(dataContext.ListProperty, textBlock.ItemsSource);
} }
} }
@ -528,7 +528,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests' xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests'
x:DataType='local:TestDataContext'> x:DataType='local:TestDataContext'>
<ItemsControl Items='{CompiledBinding ListProperty}' Name='target'> <ItemsControl ItemsSource='{CompiledBinding ListProperty}' Name='target'>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text='{CompiledBinding}' Name='textBlock' /> <TextBlock Text='{CompiledBinding}' Name='textBlock' />
@ -1782,7 +1782,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.MarkupExtensions
xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests' xmlns:local='clr-namespace:Avalonia.Markup.Xaml.UnitTests.MarkupExtensions;assembly=Avalonia.Markup.Xaml.UnitTests'
x:DataType='local:TestDataContext' x:DataType='local:TestDataContext'
x:CompileBindings='True'> x:CompileBindings='True'>
<ComboBox x:Name='comboBox' Items='{Binding GenericProperty}' SelectedItem='{Binding GenericProperty.CurrentItem}' /> <ComboBox x:Name='comboBox' ItemsSource='{Binding GenericProperty}' SelectedItem='{Binding GenericProperty.CurrentItem}' />
</Window>"; </Window>";
var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml); var window = (Window)AvaloniaRuntimeXamlLoader.Load(xaml);
var comboBox = window.FindControl<ComboBox>("comboBox"); var comboBox = window.FindControl<ComboBox>("comboBox");

8
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/BasicTests.cs

@ -505,7 +505,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
{ {
var xaml = @" var xaml = @"
<Window xmlns='https://github.com/avaloniaui'> <Window xmlns='https://github.com/avaloniaui'>
<ItemsControl Name='itemsControl' Items='{Binding}'> <ItemsControl Name='itemsControl' ItemsSource='{Binding}'>
</ItemsControl> </ItemsControl>
</Window> </Window>
"; ";
@ -522,7 +522,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
target.DataContext = items; target.DataContext = items;
Assert.Equal(items, itemsControl.Items); Assert.Equal(items, itemsControl.ItemsSource);
} }
} }
@ -760,7 +760,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
{ {
var xaml = @" var xaml = @"
<Window xmlns='https://github.com/avaloniaui'> <Window xmlns='https://github.com/avaloniaui'>
<ListBox Items='{Binding Items}' SelectedItems='{Binding SelectedItems}'/> <ListBox ItemsSource='{Binding Items}' SelectedItems='{Binding SelectedItems}'/>
</Window>"; </Window>";
var window = AvaloniaRuntimeXamlLoader.Parse<Window>(xaml); var window = AvaloniaRuntimeXamlLoader.Parse<Window>(xaml);
@ -773,7 +773,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
window.DataContext = vm; window.DataContext = vm;
Assert.Equal(vm.Items, listBox.Items); Assert.Equal(vm.Items, listBox.ItemsSource);
Assert.Equal(vm.SelectedItems, listBox.SelectedItems); Assert.Equal(vm.SelectedItems, listBox.SelectedItems);
} }

2
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/DataTemplateTests.cs

@ -74,7 +74,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
<Window xmlns='https://github.com/avaloniaui' <Window xmlns='https://github.com/avaloniaui'
xmlns:sys='clr-namespace:System;assembly=mscorlib' xmlns:sys='clr-namespace:System;assembly=mscorlib'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'> xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<ItemsControl Name='itemsControl' Items='{Binding}'> <ItemsControl Name='itemsControl' ItemsSource='{Binding}'>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<UserControl Name='foo'/> <UserControl Name='foo'/>

2
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/StyleTests.cs

@ -377,7 +377,7 @@ namespace Avalonia.Markup.Xaml.UnitTests.Xaml
}; };
var list = window.FindControl<ListBox>("list"); var list = window.FindControl<ListBox>("list");
list.Items = collection; list.ItemsSource = collection;
window.Show(); window.Show();

2
tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs

@ -391,7 +391,7 @@ namespace Avalonia.Markup.Xaml.UnitTests
</ItemsControl> </ItemsControl>
</Window> </Window>
", typeof(XamlIlBugTestsEventHandlerCodeBehind).Assembly, this); ", typeof(XamlIlBugTestsEventHandlerCodeBehind).Assembly, this);
((ItemsControl)Content).Items = new[] {"123"}; ((ItemsControl)Content).ItemsSource = new[] {"123"};
} }
} }

2
tests/Avalonia.ReactiveUI.UnitTests/AutoDataTemplateBindingHookTest.cs

@ -41,7 +41,7 @@ namespace Avalonia.ReactiveUI.UnitTests
Content = List; Content = List;
ViewModel = new ExampleViewModel(); ViewModel = new ExampleViewModel();
this.OneWayBind(ViewModel, x => x.Items, x => x.List.Items); this.OneWayBind(ViewModel, x => x.Items, x => x.List.ItemsSource);
} }
} }

Loading…
Cancel
Save