私はアプリを通じてアクティビティインジケータを持っていますが、私はこれが繰り返し見つかっています。 1つのアクティビティインジケータを定義してアプリ全体で使用できるかどうかを知りたいですか?アプリ全体に対して1つのアクティビティインジケータを表示できますか?
以下は、私がアプリに持っている5つの活動指標のうちの1つのコードです。ラベルテキストの変更を除いて、誰もがまったく同じです。
可能であれば、どこに配置するのが最適なのでしょうか?アプリのどこからでも呼び出すことができますか?
EDIT:
は、作業準備はできましたし、私が作成したコントロールで、すべての活動の指標を置き換えます。以下はコードですが、将来的に誰かを助けることができれば幸いです。バインディングと
コントロールのXAML
<?xml version="1.0" encoding="UTF-8"?>
<AbsoluteLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Myapp.ActivityBlocker"
x:Name="ActivityIndAL" IsVisible="{Binding IsBusy, Source={x:Reference ActivityIndAL}}" BackgroundColor="Black" Opacity=".75" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1">
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0,1,1" VerticalOptions="Center" HorizontalOptions="Center">
<ActivityIndicator x:Name="Activityblocker" Color="White" IsEnabled="{Binding IsBusy, Source={x:Reference ActivityIndAL}}" IsRunning="{Binding IsBusy, Source={x:Reference ActivityIndAL}}"/>
<Label Text="{Binding Text, Source={x:Reference ActivityIndAL}}" x:Name="ActivityIndLabel" TextColor="White"/>
</StackLayout>
</AbsoluteLayout>
コントロールxaml.csコントロールを使用する方法
public partial class ActivityBlocker : AbsoluteLayout
{
public ActivityBlocker()
{
InitializeComponent();
}
public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(ActivityBlocker));
public static readonly BindableProperty Running = BindableProperty.Create(nameof(IsBusy), typeof(bool), typeof(ActivityBlocker), false);
public string Text
{
get
{
return (string)GetValue(TextProperty);
}
set
{
SetValue(TextProperty, value);
}
}
public bool IsBusy
{
get
{
return (bool)GetValue(Running);
}
set
{
SetValue(Running, value);
}
}
}
:あなたはあなたがコントロールを使用する場所のcontentpageに
xmlns:control="clr-namespace:MyApp"
を追加します。コントロールとテキストを追加します。注:IsBusy = "False"は、
BindableProperty.Create
のデフォルト値がfalseなので必須ではありません。 IsBusyこの
indicator.IsBusy = true;
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:control="clr-namespace:MyApp"
....
<ContentPage.Content>
<AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<control:ActivityBlocker x:Name="indicator" Text="Processing Request" IsBusy="False"/>
</AbsoluteLayout>
</ContentPage.Content>
....
カスタムコントロール –
@YuriSを作成できます。これは完璧です。 Xamarinでカスタムコントロールを作成できるかどうかは分かりませんでした。ですから、[this](https://xamarinhelp.com/xamarin-forms-user-control/)ヘルプガイドは、私がやるべきことを言っています。正しい?もしそうなら、私は何か作業をしたら、コードを投稿して投稿します。ありがとう。 – 11011
はい、これは素晴らしい投稿です。彼はContentViewの代わりにGridをやっている。そのレイアウトが欲しいが、グリッドもあなたのために働くなら、あなたはAbsoluteLayoutをやっています。 StackLayoutが必要なのかどうかも疑問に思います。たとえばBusyTextのバインド可能なプロパティを作成し、ラベルテキスト –