3

I have a user window with 3 controls - an 'execute' button, a results control, and a processing control. My goal is to display the processing control after execute is pressed, then hide it when the execute method finishes.

However, the processing control does not display when I assumed it would... instead it only displays when (if) a callback function that creates another window prompting for user input is called.

The processing control has its visibility bound to a bool Processing in my viewmodel via BoolToVis converter. The execute method sets Processing to true at the start, then to false when it finishes. The setter of Processing calls OnPropertyChanged. My view model implements INotifyPropertyChanged.

    private bool _processing;
    public bool Processing
    {
        get
        { return _processing; }
        set
        {
            _processing = value;
            this.OnPropertyChanged("Processing");
        }
    }

    private RelayCommand _search;
    public RelayCommand Search
    {
        get { return _search ?? (_search = new RelayCommand(p => OnSearch(), p => CanSearch())); }
    }
    private void OnSearch()
    {
        this.Processing = true;

        DoWork(delegate callBack);

        this.Processing = false;
    }

And some of the XAML:

    <BooleanToVisibilityConverter x:Key="BoolToVis" />

    <me:ProcessingControl Visibility="{Binding Path=Processing, Converter={StaticResource ResourceKey=BoolToVis}}"/>
4

1 回答 1

0

使用Task或Background Worker做DoWork,在启动任务或Background Worker之前设置Processing=true,在任务结束时设置为false。这将使处理控件可见和隐藏。如果您在任务或后台工作人员中链接 bool Processing 的值,请确保您通过调度程序调用它

于 2013-10-15T16:32:17.947 回答