bugfix> c# > 投稿

プロパティのデフォルト値を復元する方法がわかりません。 カスタムタイプのプロパティに結合されているいくつかのTextBoxを含む単純なフォームがあります。 また、コマンドを使用して収集したデータをデータベースにプッシュするボタン。 問題は、ボタンをクリックしてデータベースにデータを設定した後、デフォルト値を復元できないことです。

これが私のxamlです

<TextBox Grid.Row="0" Grid.Column="2" Text="{Binding ProdusulCreat.Denumire}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Calorii" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding ProdusulCreat.Calorii}"/>
<TextBlock Grid.Row="1" Grid.Column="2" Text="Proteine" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="1" Grid.Column="3" Text="{Binding ProdusulCreat.Proteine}"/>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Sare" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding ProdusulCreat.Sare}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Grid.Column="2" Text="Zahar" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="2" Grid.Column="3" Text="{Binding ProdusulCreat.Zahar}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="3" Grid.Column="0" Text="Fibre" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding ProdusulCreat.Fibre}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="3" Grid.Column="2" Text="Grasimi" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="3" Grid.Column="3" Text="{Binding ProdusulCreat.Grasimi}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Colesterol" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding ProdusulCreat.Colesterol}" VerticalAlignment="Center"/>
<TextBlock Grid.Row="4" Grid.Column="2" Text="Carbohidrati" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox Grid.Row="4" Grid.Column="3"  Text="{Binding ProdusulCreat.Carbohidrati}" VerticalAlignment="Center"/>
<Button Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Center" Content="Adauga produsul" Command="{Binding AdaugaProdusulCommand}"/>

モデルを見る

#region Properties
#region ProdusModel : ProdusModel - Ingredientul creat
private ProdusModel _ProdusModel = new ProdusModel();
public ProdusModel ProdusulCreat
{
    get => _ProdusModel;
    set => Set(ref _ProdusModel, value);
}
#endregion
#endregion
/* ------------------------------------------------------------------------------------------------------------------------ */
#region Commands
public ICommand AdaugaProdusulCommand { get; }
private bool CanAdaugaProdusulExecute(object ob) => !string.IsNullOrEmpty(ProdusulCreat.Denumire);
private void OnAdaugaProdusulExecuted(object ob) => DataBase.AdaugaProdus(ProdusulCreat);
#endregion
public CreatorIngredienteViewModel()
{
    AdaugaProdusulCommand = new RelayCommand(OnAdaugaProdusulExecuted, CanAdaugaProdusulExecute);
}

そしてモデルの一部

public class ProdusModel
{
    public int ID { get; set; }
    public int IDSubCategorie { get; set; }
    public string Denumire { get; set; }
    public string UM { get; set; }
    public string Compozitie { get; set; }
    public double Sare { get; set; }
    public double Zahar { get; set; }
    public double Fibre { get; set; }
    public double Grasimi { get; set; }
    public double Proteine { get; set; }
    public double Colesterol { get; set; }
    public double Carbohidrati { get; set; }
    public double Calorii { get; set; }
    public int Prioritate { get; set; }
}