1

これは私の現在の設定です:

アプリケーションディレクトリを取得して別のディレクトリにコピーするコピーボタンを持つWPFアプリがあります。これが完了すると、新しい場所からアプリを起動する別のボタンができます。理想的には、コピーが完了するとボタンのテキストが「起動」に変わり、クリックするとアプリが起動するボタンが1つだけ必要です。ただし、ユーザーはボタンをもう一度クリックして再コピーできる必要がありますが、今回は「コピー」と表示されます。これは可能で、それだけの価値がありますか?

4

4 に答える 4

2

The easiest thing would be to store a state in a variable accessible from your code-behind, and have an if statement in the button's OnClick deciding what to do.

It is probably not worth the trouble, as buttons that change their meaning may be confusing to your end users. I would do two separate buttons, but I would conditionally enable or disable them, based on the state of the application. When copying is the only action that makes sense, the [Copy] button would be enabled, and the [Run] button would be disabled. When the state changes, so would the enabled/disabled status of these buttons. This would give clean visual cues to the end users of your application, and make your application easier to test automatically with various UI test automation tools.

于 2012-10-03T18:10:06.183 に答える
1

確かに可能ですが、ボタンを 2 つ持つ方がはるかに簡単に思えます。現在の状態に応じて表示を切り替えるだけで、起動できるようにするときに「起動」ボタンが表示され、コピーするときに「コピー」ボタンが表示されます。

これにより、コマンドが単純になります (各コマンドは 1 つの操作を実行します)。

于 2012-10-03T18:09:50.583 に答える
1

これを行う 1 つの方法RelayCommandは、適切な関数を呼び出す if ステートメントを使用してから使用することです。はここRelayCommandで定義されました

于 2012-10-03T18:11:09.693 に答える
1

CommandViewModelsを含む2 つを作成します。次に、そのようなモデルを含むプロパティを作成すると、は現在の のにバインドされ、は にバインドされます。次に、そのプロパティを other に変更するだけです。(これは、最初の内から行うこともできます。)CommandHeaderButton.ContentHeaderCommandViewModelButton.CommandCommandCommandViewModelCommandExecute

于 2012-10-03T18:14:00.930 に答える