Allow configuration of entry width

This commit is contained in:
TheXamlGuy
2024-06-08 23:46:19 +01:00
parent f64453232b
commit e8372f875f
16 changed files with 60 additions and 73 deletions
+1 -1
View File
@@ -15,7 +15,7 @@
SelectedValueBinding="{ReflectionBinding Value}">
<ComboBox.Styles>
<Style Selector="ComboBox.Write">
<Setter Property="MinWidth" Value="264" />
<Setter Property="MinWidth" Value="296" />
<Setter Property="IsVisible" Value="True" />
</Style>
<Style Selector="ComboBox.Read">
+1 -1
View File
@@ -9,7 +9,7 @@
<MaskedTextBox Mask="{Binding Pattern}" Text="{Binding Value}">
<TextBox.Styles>
<Style Selector="TextBox.Write">
<Setter Property="MinWidth" Value="264" />
<Setter Property="MinWidth" Value="296" />
</Style>
<Style Selector="TextBox.Read">
<Setter Property="MinWidth" Value="0" />
+1 -54
View File
@@ -6,59 +6,6 @@
x:DataType="vm:TextEntryViewModel"
Header="{Binding Key}">
<SettingsExpander.Footer>
<TextBox Text="{Binding Value}">
<TextBox.Styles>
<Style Selector="TextBox.Write">
<Setter Property="MinWidth" Value="264" />
</Style>
<Style Selector="TextBox.Read">
<Setter Property="MinWidth" Value="0" />
<Setter Property="IsReadOnly" Value="True" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Style Selector="^:pointerover">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Style Selector="^ /template/ Border#PART_BorderElement">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
</Style>
</Style>
<Style Selector="^:focus">
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Opacity="0.7" Color="{DynamicResource TextFillColorPrimary}" />
</Setter.Value>
</Setter>
<Style Selector="^ /template/ Border#PART_BorderElement">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
</Style>
</Style>
</Style>
</TextBox.Styles>
<Interaction.Behaviors>
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Read}">
<AddClassAction ClassName="Read" RemoveIfExists="True" />
<RemoveClassAction ClassName="Write" />
</DataTriggerBehavior>
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.New}">
<AddClassAction ClassName="Write" RemoveIfExists="True" />
<RemoveClassAction ClassName="Read" />
</DataTriggerBehavior>
<DataTriggerBehavior Binding="{Binding State}" Value="{x:Static vm:ItemState.Write}">
<AddClassAction ClassName="Write" RemoveIfExists="True" />
<RemoveClassAction ClassName="Read" />
</DataTriggerBehavior>
</Interaction.Behaviors>
</TextBox>
<DatePicker />
</SettingsExpander.Footer>
</SettingsExpander>
+4 -2
View File
@@ -16,7 +16,8 @@ public partial class DropdownEntryViewModel :
ItemEntryConfiguration configuration,
string key,
object value,
DropdownValueViewModel selectedItem) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value)
double width,
DropdownValueViewModel selectedItem) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value, width)
{
SelectedItem = selectedItem;
}
@@ -31,7 +32,8 @@ public partial class DropdownEntryViewModel :
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value)
object value,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, items, state, configuration, key, value, width)
{
}
}
+3 -2
View File
@@ -17,11 +17,12 @@ public class DropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
}
string? label = configuration.Label;
object? value = configuration.Value;
object? value = configuration.Value ?? "";
double? width = configuration.Width;
DropdownValueViewModel? selected = values.FirstOrDefault(x => x.Value is not null && x.Value.Equals($"{value}"));
if (serviceFactory.Create<DropdownEntryViewModel>([values, .. args.Parameters, configuration, label, value ?? "", selected])
if (serviceFactory.Create<DropdownEntryViewModel>([values, .. args.Parameters, configuration, label, value, width, selected])
is DropdownEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+12 -2
View File
@@ -26,12 +26,19 @@ public partial class ItemEntryCollectionViewModel<TItem> :
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
object value,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
{
this.configuration = configuration;
State = state;
Width = width;
}
[ObservableProperty]
private double width;
public ItemEntryCollectionViewModel(IServiceProvider provider,
IServiceFactory factory,
IMediator mediator,
@@ -42,10 +49,13 @@ public partial class ItemEntryCollectionViewModel<TItem> :
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) : base(provider, factory, mediator, publisher, subscriber, disposer, items, key, value)
object value,
double width) : base(provider, factory, mediator, publisher, subscriber, disposer, items, key, value)
{
this.configuration = configuration;
State = state;
Width = width;
}
protected override void OnValueChanged()
+3
View File
@@ -22,4 +22,7 @@ public record ItemEntryConfiguration :
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public object? Value { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? Width { get; set; } = 296;
}
+7 -3
View File
@@ -12,7 +12,8 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) :
object value,
double width) :
Observable<string, object>(provider, factory, mediator, publisher, subscriber, disposer, key, value),
IItemEntryViewModel,
INotificationHandler<UpdateEventArgs<Item>>,
@@ -22,8 +23,8 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
[ObservableProperty]
private ItemState state = state;
protected override void OnValueChanged() =>
configuration.Value = Value;
[ObservableProperty]
private double width = width;
public Task Handle(UpdateEventArgs<Item> args) =>
Task.FromResult(State = ItemState.Write);
@@ -43,4 +44,7 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
State = ItemState.Read;
return Task.CompletedTask;
}
protected override void OnValueChanged() =>
configuration.Value = Value;
}
+2 -1
View File
@@ -13,7 +13,8 @@ public partial class MaskedTextEntryViewModel(IServiceProvider provider,
ItemEntryConfiguration configuration,
string pattern,
string key,
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value)
object value,
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width)
{
[ObservableProperty]
private string pattern = pattern;
+5 -1
View File
@@ -10,7 +10,11 @@ public class MaskedTextEntryViewModelHandler(IServiceFactory serviceFactory) :
{
if (args.Value is MaskedTextEntryConfiguration configuration)
{
if (serviceFactory.Create<MaskedTextEntryViewModel>([.. args.Parameters, configuration, configuration.Pattern, configuration.Label, configuration.Value])
string? label = configuration.Label;
object? value = configuration.Value ?? "";
double? width = configuration.Width;
if (serviceFactory.Create<MaskedTextEntryViewModel>([.. args.Parameters, configuration, configuration.Pattern, label, value, width])
is MaskedTextEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+2 -1
View File
@@ -11,5 +11,6 @@ public partial class MultilineTextEntryViewModel(IServiceProvider provider,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
object value,
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
@@ -10,7 +10,11 @@ public class MultilineTextEntryViewModelHandler(IServiceFactory serviceFactory)
{
if (args.Value is MultilineTextEntryConfiguration configuration)
{
if (serviceFactory.Create<MultilineTextEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
string? label = configuration.Label;
object? value = configuration.Value ?? "";
double? width = configuration.Width;
if (serviceFactory.Create<MultilineTextEntryViewModel>([.. args.Parameters, configuration, label, value, width])
is MultilineTextEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+2 -1
View File
@@ -11,4 +11,5 @@ public partial class PasswordEntryViewModel(IServiceProvider provider,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
object value,
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
+5 -1
View File
@@ -10,7 +10,11 @@ public class PasswordEntryViewModelHandler(IServiceFactory serviceFactory) :
{
if (args.Value is PasswordEntryConfiguration configuration)
{
if (serviceFactory.Create<PasswordEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
string? label = configuration.Label;
object? value = configuration.Value ?? "";
double? width = configuration.Width;
if (serviceFactory.Create<PasswordEntryViewModel>([.. args.Parameters, configuration, label, value, width])
is PasswordEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+2 -1
View File
@@ -11,4 +11,5 @@ public partial class TextEntryViewModel(IServiceProvider provider,
ItemState state,
ItemEntryConfiguration configuration,
string key,
object value) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
object value,
double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, width);
+5 -1
View File
@@ -10,7 +10,11 @@ public class TextEntryViewModelHandler(IServiceFactory serviceFactory) :
{
if (args.Value is TextEntryConfiguration configuration)
{
if (serviceFactory.Create<TextEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
string? label = configuration.Label;
object? value = configuration.Value ?? "";
double? width = configuration.Width;
if (serviceFactory.Create<TextEntryViewModel>([.. args.Parameters, configuration, label, value, width])
is TextEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);