从 contentview 中检索 Listview 条目更新 - xamarin

问题描述

我有一个绑定到一组活动的列表视图,包括一个时间跨度,我将天数、小时数、分钟秒数划分为单独的输入字段,以便在我的内容视图中进行更新。

当我在后面的代码中单击保存并遍历列表视图时,它不会检索更新的值,只会检索原始值。如果我尝试编辑字符串,此方法工作正常,但我需要帮助来创建自定义类或绑定时间跨度字段?谁能告诉我这是怎么做的?

内容视图中的列表视图:

<ListView
                     x:Name="ActivitiesSettingsList"
                     SelectionMode="None"
                     CachingStrategy="RetainElement"
                     HasUnevenRows="True"                     
                     BackgroundColor="White"                    
                     IsPullToRefreshEnabled="False"
                     ItemsSource="{Binding UserActivitiesList }"
                     RefreshCommand="{Binding getUserActivities}"
                     IsRefreshing="{Binding IsBusy,Mode=OneWay}"                    
                     SeparatorVisibility="None"
                     RowHeight="70"                      
                    >
                    <ListView.ItemTemplate>
                        <DataTemplate >
                            <ViewCell
                                Height="60" 
                             >                                 
                                <StackLayout>
                                    <Grid BackgroundColor="White" x:Name="activitiesGrid"
                                          HeightRequest="60" WidthRequest="600" Margin="20,20,0" >

                                        <Grid.RowDeFinitions>                                                                                
                                            <RowDeFinition Height="28"/>
                                            <RowDeFinition Height="28"/>
                                            <RowDeFinition Height="1" />
                                        </Grid.RowDeFinitions>

                                        <Grid.ColumnDeFinitions>
                                            <ColumnDeFinition Width="30*"/>
                                            <ColumnDeFinition Width="15*"/>
                                            <ColumnDeFinition Width="15*"/>
                                            <ColumnDeFinition Width="15*"/> 
                                            <ColumnDeFinition Width="15*"/>
                                        </Grid.ColumnDeFinitions>

                                       <Label
                                            Grid.Row="0"                                                          
                                            Grid.Column="0"
                                            VerticalOptions="Start"
                                            FontAttributes="None"                                       
                                            Text="{Binding  .ActivityName}"
                                            Margin="0,0"
                                            TextColor="Black"                                            
                                            Padding="0,10,0"
                                            FontFamily="Hiragino Sans"
                                            FontSize="14"
                                            HeightRequest="53"
                                            BackgroundColor="White"
                                       />                                        
                                        <Entry
                                            Grid.Row="0"                                                          
                                            Grid.Column="1"
                                            VerticalOptions="Center"
                                            FontAttributes="None"                                       
                                            Text="{Binding ActivityGoalDuration.Days}"
                                            TextColor="Black"
                                            Margin="0,0"                                           
                                            FontFamily="Hiragino Sans"
                                            FontSize="14"
                                            HeightRequest="53"
                                            BackgroundColor="White"
                                       />
                                       <Entry
                                            Grid.Row="0"                                                          
                                            Grid.Column="2"
                                            VerticalOptions="Center"
                                            FontAttributes="None"                                       
                                            Text="{Binding ActivityGoalDuration.Hours}"
                                            TextColor="Black"
                                            Margin="0,0"                                           
                                            FontFamily="Hiragino Sans"
                                            FontSize="14"
                                            HeightRequest="53"
                                            BackgroundColor="White"
                                            x:Name="actDays"
                                       />
                                        <Entry
                                            Grid.Row="0"                                                          
                                            Grid.Column="3"
                                            VerticalOptions="Center"
                                            FontAttributes="None"                                       
                                            Text="{Binding ActivityGoalDuration.Minutes}"
                                            TextColor="Black"
                                            Margin="0,0"                                           
                                            FontFamily="Hiragino Sans"
                                            FontSize="14"
                                            HeightRequest="53"
                                            BackgroundColor="White"
                                       />
                                       <Entry
                                            Grid.Row="0"                                                          
                                            Grid.Column="4"
                                            VerticalOptions="Center"
                                            FontAttributes="None"                                       
                                            Text="{Binding ActivityGoalDuration.Seconds}"
                                            TextColor="Black"
                                            Margin="0,0"                                           
                                            FontFamily="Hiragino Sans"
                                            FontSize="14"
                                            HeightRequest="53"
                                            BackgroundColor="White"
                                       />
                                    </Grid>                                    
                                </StackLayout>

                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

背后的代码


List<UserActivities.Activities> list = new List<UserActivities.Activities>();

//list = (List<UserActivities.Activities>) ActivitiesSettingsList.ItemsSource.Cast<UserActivities.Activities>();

            foreach (UserActivities.Activities activityCollection in ActivitiesSettingsList.ItemsSource.Cast<UserActivities.Activities>())
            {
                var x = activityCollection.ActivityGoalDuration;
                
            }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)