-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Labels
Description
Describe the bug
My custom seperator control is not hiding when I set the IsEditable to false
<UserControl 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:actipro="http://schemas.actiprosoftware.com/avaloniaui"
xmlns:v="using:AvaloniaMario.Views"
xmlns:vm="using:AvaloniaMario.ViewModels"
mc:Ignorable="d" d:DesignWidth="320" d:DesignHeight="240"
x:Class="AvaloniaMario.Views.LayerListView"
x:DataType="vm:LayerListViewModel">
<Design.DataContext>
<!-- This only sets the DataContext for the previewer in an IDE,
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:LayerListViewModel>
</vm:LayerListViewModel>
</Design.DataContext>
<Grid RowDefinitions="*, Auto, Auto" Margin="3" RowSpacing="3">
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto">
<ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}" SelectedIndex="{Binding SelectedIndex}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="Auto, *" ColumnSpacing="3">
<CheckBox Grid.Column="0" IsChecked="{Binding IsVisible}"/>
<Label Grid.Column="1" Content="{Binding Name}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
<Grid Grid.Row="1" IsVisible="{Binding IsEditable}" ColumnDefinitions="Auto, Auto, *" ColumnSpacing="3">
<Button Grid.Column="0" MinWidth="64" Command="{Binding AddItemCommand}">Add</Button>
<Button Grid.Column="1" MinWidth="64" Command="{Binding RemoveItemCommand}">Remove</Button>
<TextBox Grid.Column="2" Text="{Binding SelectedItemName}"/>
</Grid>
<v:VSeperator Grid.Row="1" IsVisible="{Binding IsReadOnly}"/>
</Grid>
</UserControl>using System.Collections.ObjectModel;
using AvaloniaMario.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace AvaloniaMario.ViewModels;
public partial class LayerListViewModel : ViewModelBase
{
[ObservableProperty][NotifyPropertyChangedFor(nameof(IsReadOnly))] private bool _isEditable = true;
public bool IsReadOnly
{
get => !IsEditable;
set => IsEditable = !value;
}
[ObservableProperty][NotifyPropertyChangedFor(nameof(SelectedItemName), nameof(SelectedItemIsVisible))]
private ObservableCollection<LevelLayer> _items = new();
[ObservableProperty][NotifyPropertyChangedFor(nameof(SelectedItemName), nameof(SelectedItemIsVisible))]
private LevelLayer? _selectedItem = null;
[ObservableProperty][NotifyPropertyChangedFor(nameof(SelectedItemName), nameof(SelectedItemIsVisible))]
private int _selectedIndex = -1;
public string SelectedItemName
{
get => SelectedItem?.Name ?? string.Empty;
set
{
if (SelectedItem == null) return;
SelectedItem.Name = value;
}
}
public bool SelectedItemIsVisible
{
get => SelectedItem?.IsVisible ?? false;
set
{
if (SelectedItem == null) return;
SelectedItem.IsVisible = value;
}
}
[RelayCommand] private void AddItem ()
{
if (SelectedIndex != -1)
{
Items.Insert(SelectedIndex+1, new LevelLayer()
{
Name = "New Layer",
IsVisible = true,
});
}
else
{
Items.Add(new LevelLayer()
{
Name = "New Layer",
IsVisible = true,
});
}
}
[RelayCommand] private void RemoveItem()
{
if (SelectedIndex != -1)
{
var selectedIndex = SelectedIndex;
Items.RemoveAt(SelectedIndex);
SelectedIndex = selectedIndex-1;
}
else if (Items.Count > 0)
{
Items.RemoveAt(Items.Count - 1);
}
}
}<UserControl 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:v="using:AvaloniaMario.Views"
xmlns:vm="using:AvaloniaMario.ViewModels"
xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaMario.Views.VSeperator"
x:DataType="v:VSeperator">
<Panel
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
MinHeight="1"
Height="1"
Background="{actipro:ThemeResource Container5BackgroundBrush}"/>
</UserControl>using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Reactive;
namespace AvaloniaMario.Views;
public partial class VSeperator : UserControl
{
public VSeperator()
{
InitializeComponent();
DataContext = this;
}
}using AvaloniaMario.ViewModels;
using CommunityToolkit.Mvvm.ComponentModel;
namespace AvaloniaMario.Models;
public partial class LevelLayer : ModelBase
{
[ObservableProperty] private string _name = "Default";
[ObservableProperty][NotifyPropertyChangedFor(nameof(IsVisible))] private bool _isHidden;
public bool IsVisible
{
get => !IsHidden;
set => IsHidden = !value;
}
}To Reproduce
- Paste code into ide.
- make sure you have actipro free control themes nuget package installed.
- open designer and mess with the IsReadonly or IsEditable properties on the viewmodel
Expected behavior
The seperator should become invisiable when the add and remove buttons become visible.
Avalonia version
11.3.8
OS
Linux
Additional context
I did try to move the seperator out of the same grid cell as buttons still doesn't update.
Reactions are currently unavailable