WPF 「実行中」・・の表現 (Button.ClearValue)

索引サイト
実行中の表示方法と二重押しの防止

フラグ操作をマニュアルで行った場合

IsEnable だと BackGround とブリンクも無効になってしまう。




bool z_enabled = true;
private void buttonSet_Click(object sender, RoutedEventArgs e)
{
if (z_enabled == true)
{
Button w_button = (Button)e.Source;
w_button.Content = "読込中です";
w_button.Background = new SolidColorBrush(Colors.Yellow);
//**w_button.IsEnabled = false;
z_enabled = false;
DoEvents();

・・・各処理・・・

w_button.Content = "データ読込";
w_button.ClearValue(Button.BackgroundProperty);
//**w_button.IsEnabled = true;
z_enabled = true;
}
else
{
MessageBox.Show("処理中です");
}
}

つい忘れがちなソース記述




//***************************************
// 実行確認
//***************************************
private void button_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("変更します。", "確認", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
{
MessageBox.Show("中止します。");
return;
}

・・・処理・・・
}



//***************************************
// 簡易数値フォーマット
//***************************************
this.textBlock1.Text = w_count1.ToString("###0");
this.textBlock2.Text = w_count2.ToString("###0");
this.textBlock3.Text = w_count3.ToString("###0");



//***************************************
// DoEvents
//***************************************
private void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrames), frame);
Dispatcher.PushFrame(frame);
}
public object ExitFrames(object frame)
{
((DispatcherFrame)frame).Continue = false;
return null;
}



//***************************************
// ItemsSourceからの行取り出し
//***************************************
this.dataGrid.ItemsSource = w_dsWPF.Tables[0].DefaultView;

private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
DataGrid w_dataGrid = (DataGrid)e.Source;
DataRowView w_Row = (DataRowView)w_dataGrid.CurrentCell.Item;

string w_code = w_Row.Row.ItemArray[0].ToString();
string w_name = w_Row.Row.ItemArray[1].ToString();

this.textBox_code.Text = w_code;
this.textBox_name.Text = w_name;
}
catch { }
}





AX