На моей главной странице у меня установлен ActivityIndicator, когда IsBusy имеет значение true, это работает нормально, но когда я использую ту же конфигурацию на другой странице, он не запускается.
IsBusy находится в моей BaseViewModel, которая затем инициируется в ViewModelBase, мой код выглядит следующим образом ...
public class BaseViewModel : BaseSession
{
//Some other properties .....
public bool IsConnected
{
get { return _IsConnected; }
set { SetProperty(ref _IsConnected, value); }
}
public bool IsBusy
{
get { return isBusy; }
set { SetProperty(ref isBusy, value); }
}
}
ViewModelBase ...
public class ViewModelBase : BaseViewModel
{
//Lots of other Properties
}
свойства страницы ...
class BaseNetWork : ViewModelBase
{
public BaseNetWork(Grid grid, Image img, Label lbl)
{
BaseImages Images = new BaseImages();
NetworkShares NetWorkData = new NetworkShares();
img.GestureRecognizers.Add((new TapGestureRecognizer((view) => OpenShares())));
void OpenShares()
{
if (IsConnected)
{
grid.Children.Clear();
img.Source = Images.GetImages(4);
lbl.Text = "Connect";
IsConnected = false;
} else {
IsBusy = true; // Set the IsBusy to true for the ActivityIndicator.
NetWorkData.DeploySharesToGrid(grid, null, ConnectToShares);
IsConnected = true;
if (IsConnected)
{
img.Source = Images.GetImages(3);
lbl.Text = "Disconnect";
};
IsBusy = false; // Set the IsBusy back to false.
}
}
}
}
View. xaml.cs ...
public partial class FolderView : ContentPage
{
BaseImages Images = new BaseImages();
BaseNetWork viewModel;
public FolderView()
{
InitializeComponent();
BindingContext = viewModel = new BaseNetWork(GridFolders, btnConnect, lblNet);
}
void CloseEntries(object sender, EventArgs e)
{
if (viewModel.IsConnected)
{
GridFolders.Children.Clear();
btnConnect.Source = Images.GetImages(4);
lblNet.Text = "Connect";
viewModel.IsConnected = false;
}
}
}
View.xaml ...
<ScrollView>
<StackLayout Padding="{StaticResource PagePadding}" Spacing="{StaticResource PageSpacing}">
<Grid RowDefinitions="{StaticResource BrowseShareRows}" ColumnDefinitions="{StaticResource BrowseShareColumns}">
<Label x:Name="lblNet" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" HorizontalTextAlignment="Start" Text="Connect"/>
<Image x:Name="btnConnect" Grid.Row="1" Grid.Column="0" HorizontalOptions="Start" Grid.ColumnSpan="2" Source="folder_darkblue.png"></Image>
<StackLayout Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2">
<controls:Checkbox x:Name="cbHello" Text="{Binding ViewMessage}" Checked="{Binding ConnectToShares}" PropertyChanged="CloseEntries"/>
</StackLayout>
<ScrollView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5">
<StackLayout>
<Grid x:Name="GridFolders" Style="{StaticResource FolderStyle}" IsVisible="{Binding AllowViewGrid}"></Grid>
</StackLayout>
</ScrollView>
<ActivityIndicator Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="5" Color="red" IsRunning="{Binding IsBusy}"/>
</Grid>
</StackLayout>
</ScrollView>
viewthatworks.xaml.cs
public MainPage()
{
InitializeComponent();
//ConnectivityTest();
BindingContext = new ViewModelBase();
}
viewthatworks.xaml
<ScrollView>
<StackLayout Padding="{StaticResource PagePadding}" VerticalOptions="CenterAndExpand" Spacing="{StaticResource PageSpacing}">
<Grid x:Name="controlGrid" RowDefinitions="{StaticResource MainRowStyle}" ColumnDefinitions="{StaticResource MainColumnStyle}" Style="{StaticResource MainGridStyle}">
<Grid RowDefinitions="{StaticResource GridRowLayout3}" ColumnDefinitions="{StaticResource GridColumnLayout3}" >
<Entry x:Name="txtLocation" Text="{Binding GetFolder}"
Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="1"
Style="{StaticResource MainEntryStyle}"
Placeholder="Name"/>
<Button x:Name="btnSave" Text="Save Folder"
Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="1"
Style="{StaticResource MainButtonStyle}"
IsEnabled="{Binding IsNotBusy}"
Command="{Binding SaveContactCommand}"/>
<Button x:Name="btnCreate" Text="Create"
Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="1"
Style="{StaticResource MainButtonStyle}"
IsEnabled="{Binding IsNotBusy}"
Command="{Binding CreateDir}"/>
<Button x:Name="btnGrid" Text="App"
Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="1"
Style="{StaticResource MainButtonStyle}"
Clicked="Get_Grid"/>
</Grid>
</StackLayout>
<ActivityIndicator IsRunning="{Binding IsBusy}" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="6" Color="red"/>
</Grid>
</StackLayout>
</ScrollView>
Может кто-нибудь сказать, почему не работает ActivityIndicator?