Xamarin.forms 动态更改标记为进度的对话框
我想对话框,动态地改变了它的标签作为它的进展,而不拆开纸张。我查看了UserDialogs,它只在数字方面有进展。 所以我尝试过类似的方法,但只是使用了标签的最后一个设置。 你能告诉我有没有什么我错过的,或者你知道怎么做吗Xamarin.forms 动态更改标记为进度的对话框,xamarin.forms,Xamarin.forms,我想对话框,动态地改变了它的标签作为它的进展,而不拆开纸张。我查看了UserDialogs,它只在数字方面有进展。 所以我尝试过类似的方法,但只是使用了标签的最后一个设置。 你能告诉我有没有什么我错过的,或者你知道怎么做吗 class ViewModel : ObservableObject { private bool _isVisible; public bool IsVisible {
class ViewModel : ObservableObject
{
private bool _isVisible;
public bool IsVisible
{
set
{
_isVisible = value;
NotifyPropertyChanged();
}
get => _isVisible;
}
private string _loadingText = "test";
public string LoadingText
{
set
{
_loadingText = value;
NotifyPropertyChanged();
}
get => _loadingText;
}
public ViewModel()
{
_isVisible = true;
_loadingText = "test";
test();
}
public void test()
{
Thread.Sleep(200);
_loadingText = "tst20";
Thread.Sleep(200);
_loadingText = "tst8";
}
}
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="App1.LoadingDialog">
<ContentView.Content>
<Frame
CornerRadius="10"
BackgroundColor="#FFFFFF"
HorizontalOptions="CenterAndExpand"
IsVisible="{Binding IsVisible}"
VerticalOptions="CenterAndExpand">
<StackLayout>
<ActivityIndicator
IsRunning="{Binding IsVisible}"
IsVisible="{Binding IsVisible}"
VerticalOptions="CenterAndExpand"
Color="#607D8B" />
<Label
HorizontalTextAlignment="Center"
Text="{Binding LoadingText}"
TextColor="#000000"
XAlign="Center" />
</StackLayout>
</Frame>
</ContentView.Content>
</ContentView>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:App1"
x:Class="App1.MainPage">
<StackLayout>
<local:LoadingDialog/>
</StackLayout>
</ContentPage>
类视图模型:ObserveObject
{
私人住宅可见;
公共图书馆是可见的
{
设置
{
_isVisible=值;
NotifyPropertyChanged();
}
get=>\u是可见的;
}
私有字符串_loadingText=“test”;
公共字符串加载文本
{
设置
{
_loadingText=值;
NotifyPropertyChanged();
}
get=>\u加载文本;
}
公共视图模型()
{
_isVisible=true;
_loadingText=“测试”;
test();
}
公开无效测试()
{
睡眠(200);
_loadingText=“tst20”;
睡眠(200);
_loadingText=“tst8”;
}
}
我想对话框,动态地改变了它的标签作为它的进展,而不拆开纸张
我经常这样做,你可以看看:
加载dialog.xaml
<ContentView
x:Class="FormsSample.customcontrol.LoadingDialog"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentView.Content>
<Frame
x:Name="frame"
BackgroundColor="#FFFFFF"
CornerRadius="10"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<StackLayout>
<ActivityIndicator
x:Name="acin"
VerticalOptions="CenterAndExpand"
Color="#607D8B" />
<Label
x:Name="label1"
HorizontalTextAlignment="Center"
TextColor="#000000"
XAlign="Center" />
</StackLayout>
</Frame>
</ContentView.Content>
现在在contentpage中使用此自定义控件加载对话框
<StackLayout>
<local:LoadingDialog Indicator="{Binding IsVisible}" loadtext="{Binding LoadingText}" />
</StackLayout>
public partial class Page3 : ContentPage
{
public Page3()
{
InitializeComponent();
this.BindingContext = new ViewModel();
}
}
class ViewModel : ViewModelBase
{
private bool _isVisible;
public bool IsVisible
{
set
{
_isVisible = value;
RaisePropertyChanged("IsVisible");
}
get => _isVisible;
}
private string _loadingText = "test";
public string LoadingText
{
set
{
_loadingText = value;
RaisePropertyChanged("LoadingText");
}
get => _loadingText;
}
public ViewModel()
{
IsVisible = true;
LoadingText = "test";
test();
}
public async void test()
{
await Task.Delay(5000);
LoadingText = "tst20";
await Task.Delay(5000);
LoadingText = "tst8";
}
}
谢谢,我还没有机会尝试一下。但我会在我做的时候告诉你,谢谢you@RDJT有什么最新消息吗?soory做得很好
<StackLayout>
<local:LoadingDialog Indicator="{Binding IsVisible}" loadtext="{Binding LoadingText}" />
</StackLayout>
public partial class Page3 : ContentPage
{
public Page3()
{
InitializeComponent();
this.BindingContext = new ViewModel();
}
}
class ViewModel : ViewModelBase
{
private bool _isVisible;
public bool IsVisible
{
set
{
_isVisible = value;
RaisePropertyChanged("IsVisible");
}
get => _isVisible;
}
private string _loadingText = "test";
public string LoadingText
{
set
{
_loadingText = value;
RaisePropertyChanged("LoadingText");
}
get => _loadingText;
}
public ViewModel()
{
IsVisible = true;
LoadingText = "test";
test();
}
public async void test()
{
await Task.Delay(5000);
LoadingText = "tst20";
await Task.Delay(5000);
LoadingText = "tst8";
}
}
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}