mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 00:24:42 +01:00
Add buttons validations
This commit is contained in:
@@ -269,7 +269,7 @@
|
||||
<ContentDialog
|
||||
x:Name="EditVariableDialog"
|
||||
x:Uid="EditVariableDialog"
|
||||
IsPrimaryButtonEnabled="True"
|
||||
IsPrimaryButtonEnabled="{Binding Valid, Mode=OneWay}"
|
||||
IsSecondaryButtonEnabled="True"
|
||||
PrimaryButtonStyle="{StaticResource AccentButtonStyle}">
|
||||
<ContentDialog.DataContext>
|
||||
@@ -300,7 +300,7 @@
|
||||
<ContentDialog
|
||||
x:Name="AddProfileDialog"
|
||||
x:Uid="AddProfileDialog"
|
||||
IsPrimaryButtonEnabled="True"
|
||||
IsPrimaryButtonEnabled="{Binding Valid, Mode=OneWay}"
|
||||
IsSecondaryButtonEnabled="True"
|
||||
PrimaryButtonStyle="{StaticResource AccentButtonStyle}">
|
||||
<ContentDialog.DataContext>
|
||||
@@ -410,7 +410,8 @@
|
||||
<TextBox
|
||||
x:Name="AddNewVariableName"
|
||||
x:Uid="AddNewVariableName"
|
||||
Margin="0,16,0,0" />
|
||||
Margin="0,16,0,0"
|
||||
TextChanged="AddNewVariableName_TextChanged" />
|
||||
|
||||
<TextBox
|
||||
x:Name="AddNewVariableValue"
|
||||
@@ -464,10 +465,12 @@
|
||||
</controls:Case>
|
||||
</controls:SwitchPresenter>
|
||||
<Button
|
||||
x:Name="ConfirmAddVariableBtn"
|
||||
x:Uid="ConfirmAddVariableBtn"
|
||||
Grid.Row="2"
|
||||
HorizontalAlignment="Stretch"
|
||||
Command="{x:Bind AddVariableCommand}"
|
||||
IsEnabled="False"
|
||||
Style="{StaticResource AccentButtonStyle}" />
|
||||
</Grid>
|
||||
|
||||
|
||||
@@ -145,5 +145,21 @@ namespace EnvironmentVariables.Views
|
||||
ViewModel.DeleteVariable(variable, variableSet);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddNewVariableName_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
TextBox nameTxtBox = sender as TextBox;
|
||||
if (nameTxtBox != null)
|
||||
{
|
||||
if (nameTxtBox.Text.Length > 0)
|
||||
{
|
||||
ConfirmAddVariableBtn.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfirmAddVariableBtn.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace EnvironmentVariables.Models
|
||||
public partial class Variable : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(Valid))]
|
||||
private string _name;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -32,6 +33,8 @@ namespace EnvironmentVariables.Models
|
||||
|
||||
public List<string> ValuesList { get; set; }
|
||||
|
||||
public bool Valid => Validate();
|
||||
|
||||
public Variable()
|
||||
{
|
||||
}
|
||||
@@ -92,5 +95,15 @@ namespace EnvironmentVariables.Models
|
||||
ValuesList = new List<string>(ValuesList),
|
||||
};
|
||||
}
|
||||
|
||||
private bool Validate()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using EnvironmentVariables.ViewModels;
|
||||
|
||||
namespace EnvironmentVariables.Models
|
||||
{
|
||||
@@ -21,6 +23,7 @@ namespace EnvironmentVariables.Models
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(Valid))]
|
||||
private string _name;
|
||||
|
||||
[JsonIgnore]
|
||||
@@ -32,6 +35,8 @@ namespace EnvironmentVariables.Models
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<Variable> _variables;
|
||||
|
||||
public bool Valid => Validate();
|
||||
|
||||
public VariablesSet()
|
||||
{
|
||||
}
|
||||
@@ -51,5 +56,15 @@ namespace EnvironmentVariables.Models
|
||||
_ => throw new NotImplementedException(),
|
||||
};
|
||||
}
|
||||
|
||||
private bool Validate()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user