WPF Disptacher处理错误

时间:2016-03-14 09:53:41

标签: wpf

我的WPF项目中有以下xaml

<ItemsControl ItemsSource="{Binding ParentJob.JobSamples}" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Expander ExpandDirection="Down" IsExpanded="{Binding Path=IsExpanded}">
                    <Expander.Header>
                        <BulletDecorator>
                            <Label Content="{Binding Identifier}"></Label>
                        </BulletDecorator>
                    </Expander.Header>
                    <ItemsControl ItemsSource="{Binding Path=SelectedAnalyticalTests}">

                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>

                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <CheckBox Margin="4" Content="{Binding AnalyticalTestName}"  Foreground="{DynamicResource InputFontColor}" Checked="{Binding IsSelected}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Expander>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>

我的对象设置为ParentJob具有JobSample对象的ObservableCollection

和JobSample有一个名为SelectedAnalyticalTests的AnalyticalTest对象的ObservableCollection

如果我加载一个包含不包含任何SelectedAnalyticalTests的JobSamples的ParentJob,我会正确列出每个JobSamples。

如果我尝试加载具有确实具有SelectedAnalyticalTests的JobSamples的ParentJob,我会收到以下错误: -

&#39; Disptacher处理已暂停,但邮件仍在处理中

这与我的IsExpanded属性有关吗?我怎么能绕过这个?

ViewModel分为3个部分类,如下所示: -

public partial class JobRepeatViewModel : ViewModelBase
{

    public JobRepeatViewModel(MainWindowViewModel mainWindowVM)
    {

        this.MainWindowViewModel = mainWindowVM;

        try
        {
            DependencyObject dep = new DependencyObject();
            if (DesignerProperties.GetIsInDesignMode(dep))
            {
                return;
            }

            this.DA = new ACSDataAccess();

            LoadDropdowns();


        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.InnerException.ToString());
        }
    }

    private void LoadDropdowns()
    {
        this.StaffMembers = this.DA.GetStaffMembers();
    }

}

public partial class JobRepeatViewModel : ViewModelBase
{

    public void OnJobRepeatAnalysisSavePopUpClicked(object sender, RoutedEventArgs e)
    {
        if (this.OnSavePopUpClicked != null)
        {
            this.OnSavePopUpClicked(sender);
        }
    }


    public void OnJobRepeatAnalysisCancelPopUpClicked(object sender, RoutedEventArgs e)
    {
        if (this.OnCancelPopUpClicked != null)
        {
            this.OnCancelPopUpClicked(sender);
        }
    }

    public void Execute_SaveRepeatJobClick()
    {

    }
}

public partial class JobRepeatViewModel : ViewModelBase
{

    public event JobRepeatAnalysisCancelPopupClicked_Event OnCancelPopUpClicked;
    public delegate void JobRepeatAnalysisCancelPopupClicked_Event(object sender);

    public event JobRepeatAnalysisSavePopupClicked_Event OnSavePopUpClicked;
    public delegate void JobRepeatAnalysisSavePopupClicked_Event(object sender);

    public MainWindowViewModel MainWindowViewModel
    {
        get { return Get(() => MainWindowViewModel); }
        set { Set(() => MainWindowViewModel, value); }
    }

    public Job ParentJob
    {
        get { return Get(() => ParentJob); }
        set { Set(() => ParentJob, value); }
    }

    public ACSDataAccess DA
    {
        get { return Get(() => DA); }
        set { Set(() => DA, value); }
    }

    public ObservableCollection<Staff> StaffMembers
    {
        get { return Get(() => StaffMembers); }
        set { Set(() => StaffMembers, value); }
    }                           
}

0 个答案:

没有答案