Индикатор занятости не отображается в WPF MVVM?
Всем Привет,
Я пытаюсь создать
Busy indicatorво время выполнения длинных задач, но
Busy indicatorне показывает
я использую приведенный ниже код
Код XAML-это :
<UserControl x:Class="ELT_Data_Extractor.View.DataBaseBrowser" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" xmlns:viewmodel="clr-namespace:ELT_Data_Extractor.ViewModel" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="576"> <UserControl.Resources> <viewmodel:ExtractInfoVM x:Key="vm"></viewmodel:ExtractInfoVM> </UserControl.Resources> <UserControl.DataContext> <viewmodel:ExtractInfoVM></viewmodel:ExtractInfoVM> </UserControl.DataContext> <Grid Height="540"> <Grid.RowDefinitions> <RowDefinition Height="400" /> <RowDefinition Height="5" /> <RowDefinition Height="102" /> <RowDefinition Height="53*" /> </Grid.RowDefinitions> <StackPanel DataContext="{Binding Source={StaticResource vm}}"> <Grid Height="400"> <Grid.RowDefinitions> <RowDefinition Height="33*" /> <RowDefinition Height="33*" /> <RowDefinition Height="33*" /> <RowDefinition Height="89*" /> <RowDefinition Height="41*" /> <RowDefinition Height="41*" /> <RowDefinition Height="41*" /> <RowDefinition Height="18*" /> <RowDefinition Height="35*" /> <RowDefinition Height="35*" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="11" /> <ColumnDefinition Width="94" /> <ColumnDefinition Width="178*" /> <ColumnDefinition Width="261*" /> <ColumnDefinition Width="10*" /> </Grid.ColumnDefinitions> <Label Content="Vendor:" Grid.Column="1" Height="25" HorizontalAlignment="Stretch" Name="lblVendor" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,4" /> <ComboBox ItemsSource="{Binding VendorList}" SelectedValue="{Binding SelectedVendor}" Grid.Column="2" Height="23" HorizontalAlignment="Stretch" Name="cboVendor" VerticalAlignment="Center" Grid.ColumnSpan="2" Margin="0,5"> </ComboBox> <Label Content="Server:" Grid.Column="1" Height="25" HorizontalAlignment="Stretch" Name="lblServer" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,1,0,7" Grid.Row="1" /> <ComboBox Grid.Column="2" ItemsSource="{Binding Servers}" SelectedValue="{Binding SelectedServer}" Height="23" HorizontalAlignment="Stretch" Name="cboServer" VerticalAlignment="Center" Grid.ColumnSpan="2" Margin="0,3,0,7" Grid.Row="1" /> <Label Content="DataBase:" Grid.Column="1" Grid.Row="1" Height="25" HorizontalAlignment="Stretch" Name="lblDataBase" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,32,0,9" Grid.RowSpan="2" /> <ComboBox Grid.Column="2" ItemsSource="{Binding Databases}" SelectedValue="{Binding SelectedDatabase}" Grid.Row="2" Height="23" HorizontalAlignment="Stretch" Name="cboDatabase" VerticalAlignment="Center" Margin="0,1,0,9" Grid.ColumnSpan="2" /> <Label Content="Analysis:" Grid.Column="1" Grid.Row="2" Height="25" HorizontalAlignment="Stretch" Name="lblAnalysis" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,26,0,71" Grid.RowSpan="2" /> <ComboBox Grid.Column="2" ItemsSource="{Binding Analysis}" SelectedValue="{Binding SelectedAnalasis}" Grid.Row="2" Height="23" HorizontalAlignment="Stretch" Name="cboAnalysis" VerticalAlignment="Center" Margin="0,29,0,70" Grid.RowSpan="2" Grid.ColumnSpan="2" /> <TextBox Background="#FFEFECCD" Text="{Binding AnalysisInfo}" Grid.Column="2" Grid.Row="3" HorizontalAlignment="Stretch" Name="txtDesciptoin" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" TextWrapping="NoWrap" VerticalAlignment="Stretch" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" BorderThickness="2" Margin="0,24,0,0" Grid.ColumnSpan="2" /> <Label Content="Perspective:" Grid.Column="1" Grid.Row="4" Height="25" HorizontalAlignment="Stretch" Name="lblperspective" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,8" /> <ComboBox Grid.Column="2" ItemsSource="{Binding PerspectiveCodesList}" SelectedValue="{Binding SelectedPerspective}" Grid.Row="4" Height="23" HorizontalAlignment="Left" Name="cboPerspective" VerticalAlignment="Center" Width="186" Grid.ColumnSpan="2" Margin="0,9" /> <Label Content="Level:" Grid.Column="1" Grid.Row="5" Height="25" HorizontalAlignment="Stretch" Name="lblLevel" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,8" /> <!--IsEnabled="{Binding ElementName=cboVendor,Path=IsReadOnly}"--> <ComboBox Grid.Column="2" ItemsSource="{Binding LevelList}" SelectedValue="{Binding SelectedLevel}" DisplayMemberPath="LevelDescription" Grid.Row="5" Height="23" HorizontalAlignment="Left" Name="cboLevel" VerticalAlignment="Center" Width="186" Grid.ColumnSpan="2" Margin="0,9" /> <Label Content="Loss Case:" Grid.Column="1" Grid.Row="6" Height="25" HorizontalAlignment="Stretch" Name="lblLossCase" VerticalAlignment="Center" Grid.ColumnSpan="3" Margin="0,8" /> <ComboBox Grid.Column="2" Grid.Row="6" Height="23" HorizontalAlignment="Left" Name="cboLosscase" VerticalAlignment="Center" Width="186" Grid.ColumnSpan="2" Margin="0,9"> <ComboBox.Style> <Style> <Style.Triggers> <DataTrigger Binding ="{Binding ElementName=cboVendor, Path=SelectedIndex}" Value="0"> <Setter Property="ComboBox.IsEnabled" Value="false"/> </DataTrigger> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding ElementName=cboVendor, Path=SelectedIndex}" Value="1" /> </MultiDataTrigger.Conditions> <Setter Property="ComboBox.IsEnabled" Value="False" /> </MultiDataTrigger> </Style.Triggers> </Style> </ComboBox.Style> </ComboBox> <Border BorderBrush="Silver" BorderThickness="1" Grid.Column="3" Grid.RowSpan="3" Grid.Row="4" HorizontalAlignment="left" Name="border1" VerticalAlignment="Center" Width="257" Margin="17,11,0,3" Height="109"> <ListBox Name="lstReferenc" SelectedItem="{Binding Path=SelectedGranularity,UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Granularitylist, NotifyOnSourceUpdated=True}" SelectionMode="Multiple" Margin="103,8,9,8" IsEnabled="{Binding Path=AllPropertiesValid}" > <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding DetailValue}"/> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemContainerStyle> <Style TargetType="{x:Type ListBoxItem}"> <Style.Triggers> <DataTrigger Binding="{Binding IsSelected}" Value="True"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=IsSelected}"/> </Style> </ListBox.ItemContainerStyle> </ListBox> </Border> <Label Content="Granularity:" Grid.Column="3" Grid.Row="4" Height="25" HorizontalAlignment="Stretch" Margin="33,0,166,0" Name="label5" VerticalAlignment="Bottom" /> <Button Content="Select All" Command="{Binding SelectAll}" Grid.Column="3" Grid.Row="5" Height="23" HorizontalAlignment="Stretch" Margin="33,13,166,5" Name="btnSelectAll" VerticalAlignment="Center" Width="75" IsEnabled="{Binding Path=AllPropertiesValid}" /> <Button Content="Unselect All" Grid.Column="3" Grid.Row="6" Height="23" HorizontalAlignment="Stretch" Command="{Binding UnSelectAll}" Name="btnUnselectAll" VerticalAlignment="Top" Width="75" Margin="33,8,166,0" IsEnabled="{Binding Path=AllPropertiesValid}" /> <Label Content="File Name:" Grid.Column="1" Grid.Row="7" Height="25" HorizontalAlignment="Stretch" Name="label7" VerticalAlignment="Center" /> <TextBox Grid.Row="7" Height="25" Name="txtName" Grid.Column="2" Text="{Binding FileName}" Grid.ColumnSpan="2" Margin="0,0,0,28" Grid.RowSpan="2" /> <Label Content="Folder:" Grid.Column="1" Grid.Row="8" Height="25" HorizontalAlignment="Stretch" Name="label8" VerticalAlignment="Center" /> <!--EJG comment: Bind Folder textbox to member property ("FilePath") in ExtractInfo object model (similar to FileName)--> <TextBox Grid.Row="8" Height="25" Name="txtPath" IsReadOnly="True" Grid.Column="2" Text="{Binding OutputPath,ValidatesOnDataErrors=True}" Grid.ColumnSpan="2" Margin="0,5" /> <Button Grid.Column="3" Content="(...)" Command="{Binding FileBrowse}" Grid.Row="8" HorizontalAlignment="Right" Name="btnBrowse" Width="40" VerticalAlignment="Center" Margin="0,7" /> <Button Content="Generate" Command="{Binding GenerateReport}" Grid.Column="3" Grid.Row="9" Height="25" HorizontalAlignment="Right" Name="btnGenerate" VerticalAlignment="Center" Width="100" Margin="0,5" /> <xctk:BusyIndicator IsBusy="{Binding BackgroundProcess}" BusyContent="Extracting Data..." > </xctk:BusyIndicator> </Grid> </StackPanel> <GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Margin="0,0,10,0" /> <StackPanel Grid.Row="2" Grid.RowSpan="2" DataContext="{Binding Source={StaticResource vm}}" Margin="0,0,0,34"> <DataGrid x:Name="grdfilelist" AutoGenerateColumns="False" ItemsSource="{Binding ELTFileList}" Margin="10,2,8,51" Height="97" CanUserAddRows="False"> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <Grid> <Button Margin="3" Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding ConverterParameter=parameter}"> <ToolTipService.ToolTip> <ToolTip Content="Remove File" /> </ToolTipService.ToolTip> <Image Height="12" Width="12" Stretch="Uniform" Source="/Images/Delete.PNG" /> </Button> </Grid> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header="FileName" Binding="{Binding FileName}"/> <DataGridTextColumn Header="Path" Binding="{Binding FilePath}" /> </DataGrid.Columns> </DataGrid> </StackPanel> </Grid> </UserControl>
Мой код C# является
private bool _backgroundprocess; public bool BackgroundProcess { get { return _backgroundprocess; } set { if (value != _backgroundprocess) { _backgroundprocess = value; OnPropertyChanged("BackgroundProcess"); } } } public ObservableCollection<lossextractor.extractinfo> ExportData() { backgroundprocess = true; ///My code is here backgroundprocess = false; }
Что я уже пробовал:
я пытался реализовать в главном окне его работу нормально
Graeme_Grant
Здорово, что вы разместили код, но здесь его слишком много!