[英]How to update a progress bar based on a form in WinRT?
I have a form containing few TextBox elements and a progress bar. 我有一个包含几个TextBox元素和一个进度栏的表单。 I want the progress bar to be updated when the TextBox have some values assigned.
我希望在为TextBox分配一些值时更新进度条。
I noticed that in WPF this can be achieved using BackgroundWorker, but this doesn't exist in WinRT 我注意到在WPF中可以使用BackgroundWorker来实现,但这在WinRT中不存在
XAML: XAML:
<StackPanel>
<ProgressBar x:Name="progressBar1"
Value="{Binding ProgressPercent}"
HorizontalAlignment="Left"
IsIndeterminate="False"
Maximum="100" />
<TextBlock Text="Name" Grid.Column="0"/>
<TextBox x:Name="NameTextBox" Text="{Binding Name, Mode=TwoWay}"/>
<TextBlock Text="Data" Grid.Row="1" Grid.Column="0"/>
<DatePicker Date="{Binding Data, Mode=TwoWay}"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Grid.Row="1"
Grid.Column="1"
CalendarIdentifier="GregorianCalendar"
Margin="0,8" />
<TextBlock Text="Address" Grid.Row="2" Grid.Column="0"/>
<TextBox x:Name="AddressTextBox"
Text="{Binding Address, Mode=TwoWay}"
Grid.Row="2"
Grid.Column="1"
Margin="0,5" />
<TextBlock Text="Email" Grid.Row="3" Grid.Column="0"/>
<TextBox x:Name="EmailTextBox"
Text="{Binding Email, Mode=TwoWay}"
Grid.Row="3"
Grid.Column="1"
Margin="0,5" />
</StackPanel>
ViewModel: ViewModel:
#region fields
private string progressPercent {get;set;}
#endregion
#region proprietes
public int ProgressPercent
{
get
{
return this.progressPercent;
}
set
{
this.progressPercent = value;
this.RaisePropertyChanged(() => this.ProgressPercent);
}
}
#endregion
How can this be achieved in WinRT? 在WinRT中如何实现? Most of the examples are for Wpf unfortunately
不幸的是,大多数示例都是针对Wpf的。
Each time one of the form's fields got updated a percent value needs to be added to the ProgressPercent property, i don't see the need for an async code, but if you insisted on that here how to do it 每次表单的一个字段更新时,都需要将一个百分比值添加到ProgressPercent属性中,我看不到需要异步代码,但是如果您坚持要这样做,那么该怎么做
private string _name = "";
public string Name
{
get
{
return _name;
}
set
{
if (_name == value)
{
return;
}
_name = value;
OnPropertyChanged();
Window.Current.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
{
ProgressPercent += 10; //handle the fact that this needs to be added once using a bool or something
});
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.