Displaying an observable collection on a templated control

I have an Avalonia Templated control that has a Styled Property of “Value” that is a string. It’s purpose is to accept a series of tags that are separated by spaces. I would like to split that string and show the individual tags in an item control (or item repeater).

So – I wrote code to catch the changes to “Value” and split out the values and put them in an observable collection. I know that the collection is being populated correctly, but I cannot get it to display on the control.

I’ve tried making the collection as an observablecollection, avalonialist, styled property, direct property, etc. Also tried templatebinding vs binding to the parent for the itemscontrol.

Any thoughts on what I am doing wrong?

public class FormTagControl : TemplatedControl
{
    public static readonly StyledProperty<string> ValueProperty =
    AvaloniaProperty.Register<FormTagControl, string>(nameof(Value), defaultBindingMode: BindingMode.TwoWay);

    public static readonly StyledProperty<bool> ShowEditModeProperty =
    AvaloniaProperty.Register<FormTagControl, bool>(nameof(ShowEditMode), defaultBindingMode: BindingMode.TwoWay);

    public static readonly StyledProperty<bool> ShowAddButtonProperty =
    AvaloniaProperty.Register<FormTagControl, bool>(nameof(ShowEditMode), defaultBindingMode: BindingMode.TwoWay);

    public static readonly StyledProperty<string> ErrorMessageProperty =
    AvaloniaProperty.Register<FormTagControl, string>(nameof(ErrorMessage), defaultBindingMode: BindingMode.OneWay);

    public static readonly StyledProperty<string> LabelProperty =
        AvaloniaProperty.Register<FormTagControl, string>(nameof(Label), defaultBindingMode: BindingMode.OneWay);

    public static readonly StyledProperty<string> WatermarkProperty =
        AvaloniaProperty.Register<FormTagControl, string>(nameof(Watermark), defaultBindingMode: BindingMode.OneWay);

    public ObservableCollection<string> Tags { get; set; } = new();

    protected bool ShowEditMode
    {
        get => GetValue(ShowEditModeProperty);
        set => SetValue(ShowEditModeProperty, value);
    }

    protected bool ShowAddButton
    {
        get => GetValue(ShowAddButtonProperty);
        set => SetValue(ShowAddButtonProperty, value);
    }

    public string Value
    {
        get => GetValue(ValueProperty);
        set => SetValue(ValueProperty, value);
    }

    public string ErrorMessage
    {
        get => GetValue(ErrorMessageProperty);
        set => SetValue(ErrorMessageProperty, value);
    }

    public string Label
    {
        get => GetValue(LabelProperty);
        set => SetValue(LabelProperty, value);
    }

    public string Watermark
    {
        get => GetValue(WatermarkProperty);
        set => SetValue(WatermarkProperty, value);
    }

    protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
    {
        var btnGoToEditMode = e.NameScope.Find<Button>("PART_GoToEditModeButton");
        var btnGoToViewMode = e.NameScope.Find<Button>("PART_GoToViewModeButton");
        var btnAddTags = e.NameScope.Find<Button>("PART_AddButton");

        if (btnGoToEditMode is not null)
        {
            btnGoToEditMode.Click += (s, e) =>
            {
                ShowEditMode = true;
            };
        }

        if (btnGoToViewMode is not null)
        {
            btnGoToViewMode.Click += (s, e) =>
            {
                ShowEditMode = false;
            };
        }

        if (btnAddTags is not null)
        {
            btnAddTags.Click += (s, e) =>
            {
                ShowEditMode = true;
            };
        }

        base.OnApplyTemplate(e);
    }

    protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
    {
        if (change.Property.Name == nameof(Value))
        {
            if (string.IsNullOrEmpty(change.NewValue?.ToString()))
            {
                ShowAddButton = true;
            }
            else
            {
                ShowAddButton = false;
            }

            BuildTagList();
        }

        base.OnPropertyChanged(change);
    }

    protected void BuildTagList()
    {
        Tags.Clear();

        string[] tagValues = Value.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        foreach (string tagValue in tagValues)
        {
            Tags.Add(tagValue);
        }
    }
}
<Styles xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="https://github.com/projektanker/icons.avalonia"
        xmlns:controls="using:NRS.UI.Mvvm.FormControls">
    <Design.PreviewWith>
        <controls:FormTagControl />
    </Design.PreviewWith>

    <Style Selector="controls|FormTagControl">
        <!-- Set Defaults -->
        <Setter Property="Template">
            <ControlTemplate>
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                        <RowDefinition></RowDefinition>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Row="0" Classes="NRSLabel" Text="{TemplateBinding Label}"></TextBlock>

                    <Grid Grid.Row="1" IsVisible="{TemplateBinding ShowEditMode}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <Button i:Attached.Icon="fa-solid fa-grip" Grid.Column="0" Name="PART_GoToViewModeButton" Classes="NoStyling" Height="38">
                        </Button>

                        <TextBox Grid.Column="1" Watermark="{TemplateBinding Watermark}"
                            Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"/>
                    </Grid>

                    <Grid Grid.Row="1" IsVisible="{TemplateBinding ShowEditMode,Converter={x:Static BoolConverters.Not}}">
                        <Button Name="PART_GoToEditModeButton" Classes="NoStyling" Height="38"
                                IsVisible="{TemplateBinding ShowAddButton,Converter={x:Static BoolConverters.Not}}">
                            <ItemsControl Margin="0 40 0 0" ItemsSource="{Binding Tags, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <WrapPanel />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>

                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Button>
                        <Button Name="PART_AddButton" Height="38"
                                IsVisible="{TemplateBinding ShowAddButton}">
                            <Label>Add Tags</Label>
                        </Button>
                    </Grid>

                    <TextBlock Grid.Row="2" Classes="NRSErrorMessage" Text="{TemplateBinding ErrorMessage}" />
                </Grid>
            </ControlTemplate>
        </Setter>
    </Style>
</Styles>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật