Skip to content

Commit

Permalink
Add BehaviorCollectionTemplate page
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Dec 31, 2024
1 parent 872be7f commit 5532cdb
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
3 changes: 3 additions & 0 deletions samples/BehaviorsTestApplication/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
<TabItem Header="Sliding Animation">
<pages:SlidingAnimationView />
</TabItem>
<TabItem Header="BehaviorCollectionTemplate">
<pages:BehaviorCollectionTemplateView />
</TabItem>
</TabControl>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<UserControl x:Class="BehaviorsTestApplication.Views.Pages.BehaviorCollectionTemplateView"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:BehaviorsTestApplication.ViewModels"
x:CompileBindings="True" x:DataType="vm:MainWindowViewModel"
mc:Ignorable="d" d:DesignWidth="600" d:DesignHeight="450">
<Design.DataContext>
<vm:MainWindowViewModel />
</Design.DataContext>
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.Styles>
<Style Selector="ItemsControl > ContentPresenter" x:DataType="vm:ItemViewModel">
<Setter Property="(Interaction.Behaviors)">
<BehaviorCollectionTemplate>
<BehaviorCollection>
<EventTriggerBehavior EventName="PointerPressed">
<PopupAction>
<Border Background="White"
BorderBrush="Black"
BorderThickness="1"
Padding="10">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Value: " />
<TextBlock Text="{Binding Value}" />
</StackPanel>
</Border>
</PopupAction>
</EventTriggerBehavior>
</BehaviorCollection>
</BehaviorCollectionTemplate>
</Setter>
</Style>
<Style Selector="ItemsControl > ContentPresenter">
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="5" />
</Style>
</ItemsControl.Styles>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="vm:ItemViewModel">
<TextBlock Text="{Binding Value}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;

namespace BehaviorsTestApplication.Views.Pages;

public partial class BehaviorCollectionTemplateView : UserControl
{
public BehaviorCollectionTemplateView()
{
InitializeComponent();
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

0 comments on commit 5532cdb

Please sign in to comment.