c# - 当我输入条目时,轮播视图将我滚动到第一个项目
问题描述
我正在创建一个移动 android 应用程序,在其中我使用轮播查看并显示来自服务器的数据,用户需要从机器输入数据并验证机器的数据是否与服务器接收的数据相同并保存。
我根据服务器接收到的数据使用数据模板,它工作正常。
XAML:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Manual_Logger.Checklist"
xmlns:viewmodels1="clr-namespace:Manual_Logger.ViewModel" xmlns:selector="clr-namespace:Manual_Logger.Control"
NavigationPage.HasNavigationBar="False"
BackgroundColor="#E9ECEF">
<ContentPage.BindingContext>
<viewmodels1:Tour_TagViewModel/>
</ContentPage.BindingContext>
<ContentPage.Resources>
<ResourceDictionary>
<!-- Parammeters Template-->
<DataTemplate x:Key="parameterViewTemplate">
<StackLayout x:Name="stackTest">
<Frame BackgroundColor="#f8f9fa" HasShadow="True"
BorderColor="DarkGray"
CornerRadius="5"
Margin="0"
HeightRequest="350"
WidthRequest="300"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<ScrollView>
<StackLayout >
<!-- Insert Text if it is only text -->
<Label Text="Texto Esperado"
x:Name="txtEsperado"
FontSize="Medium"
FontAttributes="Italic"
HorizontalOptions="Start"/>
<!-- Display data -->
<Frame x:Name="frame" CornerRadius="5" Padding="2">
<Label Text="{Binding Parameter}"
x:Name="expectedValues"
FontSize="Medium"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Frame >
<!-- Type data by user -->
<Label Text="Valor:"
FontSize="Medium"
FontAttributes="Italic"
HorizontalOptions="Start"/>
<Frame CornerRadius="5" Padding="0" >
<Entry FontSize="Medium"
WidthRequest="250"
HorizontalTextAlignment="Center"
HorizontalOptions="Center"
VerticalOptions="Center"
x:Name="entryPosicion"/>
</Frame>
</StackLayout>
</ScrollView>
</Frame>
</StackLayout>
</DataTemplate>
<!-- Range Template -->
<DataTemplate x:Key="rangeViewTemplate">
<StackLayout>
<Frame BackgroundColor="#f8f9fa" HasShadow="True"
BorderColor="DarkGray"
CornerRadius="5"
Margin="0"
HeightRequest="350"
WidthRequest="300"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<ScrollView>
<StackLayout>
<!--Insert if are numeric values-->
<Label Text="Valor Maximo Esperado"
x:Name="txtValorMaximo"
FontSize="Medium"
FontAttributes="Italic"
HorizontalOptions="Start"/>
<Frame CornerRadius="5" Padding="2" >
<Label Text="{Binding Tag_Name_Maximum_Expected}"
x:Name="showValorMaximo"
FontSize="Medium"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Frame>
<Label Text="Valor Minimo Esperado"
x:Name="txtValorMinimo"
FontSize="Medium"
FontAttributes="Italic"
HorizontalOptions="Start"/>
<Frame CornerRadius="5" Padding="2" >
<Label Text="{Binding Tag_Name_Minimum_Expected}"
x:Name="showValorMinimo"
FontSize="Medium"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Frame>
<!-- Type data by user -->
<Label Text="Valor:"
FontSize="Medium"
FontAttributes="Italic"
HorizontalOptions="Start"/>
<Frame CornerRadius="5" Padding="0" >
<Entry FontSize="Medium"
WidthRequest="250"
HorizontalTextAlignment="Center" HorizontalOptions="Center"
VerticalOptions="Center"x:Name="entryPosicion"/>
</Frame>
</StackLayout>
</ScrollView>
</Frame>
</StackLayout>
</DataTemplate>
<selector:MyDataTemplateSelector x:Key="mainTemplate" ParameterTemplate="{StaticResource parameterViewTemplate}" RangeTemplate="{StaticResource rangeViewTemplate}">
</selector:MyDataTemplateSelector>
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout x:Name="parametersStack" Margin="0, 5 ,0,0">
<Label Text="{Binding Tag_Name}" Margin="25, 20, 15, 0" FontSize="27" HorizontalOptions="Start"/>
<Frame CornerRadius="3" BackgroundColor="white" Margin="15, 5, 15, 30" Padding="5, 10 , 5 , 10">
<Grid BackgroundColor="White">
<Grid.RowDefinitions>
<RowDefinition Height="430"/>
</Grid.RowDefinitions>
<CarouselView IndicatorView="indicatorView" ItemsSource="{Binding Get_Tour_Run_Tags}" ItemTemplate="{DynamicResource mainTemplate}" x:Name="lstData">
</CarouselView>
<IndicatorView x:Name="indicatorView" MaximumVisible="15" Margin="0,0,0,7"/>
</Grid>
</Frame>
</StackLayout>
</ContentPage>
后面的代码:
public partial class Checklist : ContentPage
{
public Checklist()
{
InitializeComponent();
}
}
模型:
*public class Tour_Tag
{
public Guid Tour_Id
{
get;
set;
}
public string Limit_Type
{
get;
set;
}
public string Parameter
{
get;
set;
}
public string Tag_Name_Minimum_Expected
{
get;
set;
}
public string Tag_Name_Maximum_Expected
{
get;
set;
}
}*
视图模型:
public class Tour_TagViewModel : INotifyPropertyChanged
{
readonly IList<Tour_Tag> source;
public ObservableCollection<Tour_Tag> Get_Tour_Run_Tags { get; private set; }
public Tour_Tag CurrentItem { get; set; }
public int Position { get; set; }
public Tour_TagViewModel()
{
source = new List<Tour_Tag>();
CreateTourTagsCollection();
CurrentItem = Get_Tour_Run_Tags.Skip(3).FirstOrDefault();
OnPropertyChanged("CurrentItem");
Position = 3;
OnPropertyChanged("Position");
}
private void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
void CreateTourTagsCollection()
{
// V = Parammeters, M = Range, F = Scann
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer", Parameter = "R-EP01982_X6-T" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.PCB Part Number", Parameter = "EP01982 + BP1" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Stencil ID", Parameter = "SE3258-AXN [Rack LF - 7]" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Board Lock Fixture", Parameter = "PINES(YAMAHA) ,SE2726-AXN [Gaveta B - 32]" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Stencil Clean Rate", Parameter = "5" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Solder Paste Number", Parameter = "250" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Squeegee Dimensions", Parameter = "ROH-LOCTITE" });
source.Add(new Tour_Tag { Limit_Type = "M", Tag_Name = "L5 Paste Printer.Squeegee Speed", Tag_Name_Maximum_Expected = "100", Tag_Name_Minimum_Expected = "80" });
source.Add(new Tour_Tag { Limit_Type = "M", Tag_Name = "L5 Paste Printer.Squeegee Contact Angle", Tag_Name_Maximum_Expected = "60", Tag_Name_Minimum_Expected = "50" });
source.Add(new Tour_Tag { Limit_Type = "M", Tag_Name = "L5 Paste Printer.Squeegee Pressure", Tag_Name_Maximum_Expected = "120", Tag_Name_Minimum_Expected = "100" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Distance Separation", Parameter = "1" });
source.Add(new Tour_Tag { Limit_Type = "V", Tag_Name = "L5 Paste Printer.Separation Speed", Parameter = "5" });
Get_Tour_Run_Tags = new ObservableCollection<Tour_Tag>(source);
}
public event PropertyChangedEventHandler PropertyChanged;
}
这里的问题是,如果我输入一个条目,轮播会将我滚动回第一个项目。
我想要做的是输入每个项目的条目,这样我就可以输入我想要的数据并保存它。
抱歉,如果这是一个非常愚蠢的问题,但我是新手。
这是一个要清楚的例子。
解决方案
推荐阅读
- javascript - 科尔多瓦ios中的谷歌地图方向问题
- python - kmeans.cluster() 在对句子使用 wordembedding (word2vec) 时给出错误“TypeError: 'float' object is not iterable”
- c# - 如何从字符串的开头和结尾删除不可见的 unicode 字符?
- java - 如何在使用 java 代码上传到 Bugzilla 工具时获得图像的实际颜色而不会出现任何失真?
- java - 如何在java正则表达式中匹配字符串或空格的结尾
- python - OSError:无法打开文件(无法打开文件:名称 = 'DLCB_code_output/Results_mmWave_ML0',errno = 13,错误消息 = 'Permission denied')
- typescript - 警告 任何意外。指定不同的类型 @typescript-eslint/no-explicit-any 或属性 'map' 不存在于类型 'string'.ts(2339)
- javascript - 如何在反应中使用 if else 语句验证 RegExp?
- ios13 - 我们是否应该在ios13中为暗模式和亮模式添加两个图像
- powershell - 如何使用 powereshell 在 Jenkinsfile 中打印当前工作目录