プロパティのデフォルト値を復元する方法がわかりません。 カスタムタイプのプロパティに結合されているいくつかの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; }
}
回答 1 件
関連記事
- Puppetのデフォルト値を持つ複雑な構造
- typescriptでプロトタイプを拡張するときにデフォルトのパラメータ値を使用するにはどうすればよいですか?
- 単一のカスタム投稿タイプページに複数のカスタム分類値を表示しますか?
- cloud initconfigを使用して/ etc/ssh/sshd_configのデフォルト値を変更する
- cloud initconfigを使用して/ etc/ssh/sshd_configのデフォルト値を変更する
- ラジオボタンに基づくMatselectのデフォルト値
- jQuery:カスタムヘッダー値を使用してテーブルのJSONデータを取得する方法
- 検証ルールのデフォルトのツールチップのカスタムテンプレートを作成するにはどうすればよいですか?
- カスタムカーネルを介してcuda - : gpumat値を変更する
関連した質問
- 特定の条件が適用される場合にボタンを有効にする
- WPF ListViewの水平スクロールバーは、垂直スクロールが行われない限り表示されません。
- MVVM ListViewSelectedItemプロパティ
- 特定のテキストの後にテキストファイルを1行ずつ一時リストに保存する方法
- RadioButtons/Checkboxを2列に分割します
- 数字のみのC#テキストボックス
- C#DateTime + TimeSpan =追加の12時間?
- NETSDK1135サポートされているOSPlatformVersion100190410をTargetPlatformVersion70より高くすることはできません
- WPFアプリクラスから変数にアクセスするための推奨される方法
現在のインスタンスを保存した後、新しいモデルを作成します。
すべてのプロパティはデフォルト値で初期化されます。 ProdusulCreatプロパティは通知を実装するため、ビューが更新され、それらのデフォルト値が表示されます