Editing WIP

This commit is contained in:
TheXamlGuy
2024-05-22 21:57:30 +01:00
parent 67c07a9902
commit 50886379b6
9 changed files with 63 additions and 24 deletions
+1 -1
View File
@@ -52,7 +52,7 @@
BorderThickness="1,1,0,0"
CornerRadius="8 0 0 0">
<Grid RowDefinitions="Auto, *">
<Border Grid.Row="0" Padding="4">
<Border Grid.Row="0" Padding="4" Height="44">
<ContentControl>
<Interaction.Behaviors>
<AttachedBehaviour>
+26 -8
View File
@@ -11,15 +11,33 @@
DisplayName="{Binding Value}" />
<TextBox
MaxWidth="360"
IsVisible="{Binding !Immutable}"
IsReadOnly="{Binding Immutable, Mode=TwoWay}"
Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"
TextAlignment="Center"
Watermark="Enter name" />
<SelectableTextBlock
MaxWidth="360"
IsVisible="{Binding Immutable}"
SelectionBrush="Red"
Text="{Binding Value}"
TextAlignment="Center" />
Watermark="Enter name">
<TextBox.Styles>
<Style Selector="TextBox[IsReadOnly=True]">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Style Selector="^:pointerover">
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundPointerOver}" />
<Style Selector="^ /template/ Border#PART_BorderElement">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
</Style>
</Style>
<Style Selector="^:focus">
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
<Style Selector="^ /template/ TextBlock#PART_Watermark">
<Setter Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundFocused}" />
</Style>
<Style Selector="^ /template/ Border#PART_BorderElement">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
</Style>
</Style>
</TextBox.Styles>
</TextBox>
</StackPanel>
</UserControl>
+4 -4
View File
@@ -9,10 +9,10 @@ public class AggerateItemViewModelHandler(IMediator mediator,
{
public Task Handle(AggerateEventArgs<IItemEntryViewModel> args)
{
if (serviceFactory.Create<ItemHeaderViewModel>(false) is ItemHeaderViewModel viewModel)
{
publisher.Publish(Create.As<IItemEntryViewModel>(viewModel), nameof(ItemViewModel));
}
//if (serviceFactory.Create<ItemHeaderViewModel>(false) is ItemHeaderViewModel viewModel)
//{
// publisher.Publish(Create.As<IItemEntryViewModel>(viewModel), nameof(ItemViewModel));
//}
return Task.CompletedTask;
}
+1 -1
View File
@@ -11,5 +11,5 @@ public partial class EditItemActionViewModel(IServiceProvider provider,
IDisposer disposer) : Observable(provider, factory, mediator, publisher, subscriber, disposer)
{
[RelayCommand]
public void Invoke() => Publisher.Publish(Edit.As<Item>(), nameof(ItemViewModel));
public void Invoke() => Publisher.Publish(Edit.As<Item>());
}
+1 -1
View File
@@ -4,6 +4,6 @@ public record Item
{
public Guid Id { get; init; }
public string Name { get; init; } = "";
public string? Name { get; init; } = "";
}
+1 -1
View File
@@ -2,5 +2,5 @@
public record ItemConfiguration
{
public string Name { get; set; } = "";
public string? Name { get; set; } = "";
}
+1 -1
View File
@@ -2,5 +2,5 @@
public record ItemHeaderConfiguration
{
public string Name { get; init; } = "";
public string? Name { get; init; } = "";
}
+13 -6
View File
@@ -13,7 +13,10 @@ public partial class ItemHeaderViewModel(IServiceProvider provider,
string? value = null) : Observable<string, string>(provider, factory, mediator, publisher, subscriber, disposer, value),
IHandler<ValidationEventArgs<Item>, bool>,
IHandler<ConfirmEventArgs<Item>, ItemHeaderConfiguration>,
IItemEntryViewModel, IRemovable
INotificationHandler<EditEventArgs<Item>>,
INotificationHandler<ConfirmEventArgs<Item>>,
INotificationHandler<CancelEventArgs<Item>>,
IItemEntryViewModel
{
[ObservableProperty]
private bool immutable = immutable;
@@ -24,11 +27,15 @@ public partial class ItemHeaderViewModel(IServiceProvider provider,
return Task.FromResult(true);
}
public override void Dispose()
{
base.Dispose();
}
public Task<ItemHeaderConfiguration> Handle(ConfirmEventArgs<Item> args,
CancellationToken cancellationToken) => Task.FromResult(new ItemHeaderConfiguration { Name = Value });
public Task Handle(EditEventArgs<Item> args) =>
Task.FromResult(Immutable = false);
public Task Handle(CancelEventArgs<Item> args) =>
Task.FromResult(Immutable = true);
public Task Handle(ConfirmEventArgs<Item> args) =>
Task.FromResult(Immutable = true);
}
+15 -1
View File
@@ -3,10 +3,10 @@ using Toolkit.Foundation;
namespace Bitvault;
[Aggerate(nameof(ItemViewModel))]
public partial class ItemViewModel :
ObservableCollection<IItemEntryViewModel>,
INotificationHandler<EditEventArgs<Item>>,
INotificationHandler<ConfirmEventArgs<Item>>,
INotificationHandler<CancelEventArgs<Item>>
{
[ObservableProperty]
@@ -43,6 +43,8 @@ public partial class ItemViewModel :
Favourite = favourite;
Archived = archived;
Name = name;
Add<ItemHeaderViewModel>(immutable, name);
}
public IContentTemplate Template { get; set; }
@@ -69,6 +71,18 @@ public partial class ItemViewModel :
return Task.CompletedTask;
}
public Task Handle(ConfirmEventArgs<Item> args)
{
Publisher.Publish(Notify.As(Factory.Create<CommandCollection>(new List<IDisposable>
{
Factory.Create<FavouriteItemActionViewModel>(Favourite),
Factory.Create<EditItemActionViewModel>(),
Factory.Create<ArchiveItemActionViewModel>(),
})));
return Task.CompletedTask;
}
public override Task OnActivated()
{
if (!Immutable)