无法在网格中使用 ObservableCollection?

发布于 2025-01-18 12:12:03 字数 2568 浏览 0 评论 0原文

我目前正在使用Xamarin应用程序来读取RFID温度标签并实时更新其值。当前的设置使用两个水平堆叠式,一种带有listView,显示标签及其值列表,另一个带有人体图像的网格,我也希望在特定的位置显示该值。

在ListView端,我可以成功调用一个名为Taginfolist的对象,这是我从BasePage初始化中调用的类中的观察力授权。但是,在网格侧,我尝试了使用Taginfolist的多种方法,但它不起作用。我已经尝试了BindableLayout,DataTemplates + ViewCells,并且没有一个允许我在第二个堆栈中获得Taginfolist可用。

这是两个水平堆叠式的XAML代码:

<StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
          <ListView x:Name="liewViewTagData" ItemsSource="{Binding TagInfoList}" SelectedItem="{Binding objItemSelected, Mode=TwoWay}">
            <ListView.Header>
              <StackLayout BackgroundColor="#cccccc">
                <Grid>
                  <!-- Grid + Label code irrelevant to my issue-->
                </Grid>
              </StackLayout>
            </ListView.Header>

            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                  <StackLayout Orientation="Vertical">
                    <Grid>
                      <!-- Grid + Label code irrelevant to my issue-->
                    </Grid>
                  </StackLayout>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>
        </StackLayout> <!-- RFID Tag Section -->

        <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand"> <!-- Body Model Section -->
          <!-- HERE: WHAT TO PUT FOR TagInfoList TO BE USABLE? -->
          <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" WidthRequest="400" ColumnSpacing="0">
             <!-- Grid + Label + Images I want to use TagInfoList information in -->
          </Grid>
          <!-- HERE: WHAT TO PUT FOR TagInfoList TO BE USABLE? -->
        </StackLayout> <!-- Body Model Section -->
      </StackLayout>```

由于它不相关,因此我删除了大部分内部网格。 Taginfolist是一个类的观测值,其中包含我需要的所有数据(字符串和INT)。如何在第二个堆栈中使用taginfolist?如果我这样做的方法与第一个堆叠式的方法相同,那么我会得到我两次称为taginfolist的错误(通过“ liewviewtagdata”项目)。这是.xaml.cs文件中的代码:

liewViewTagData.ItemSelected += (sender, e) => {
                if (e.SelectedItem == null) return;     // Don't do anything if we just de-selected the row
                ((ListView)sender).SelectedItem = null; // De-select the row
            };

我的唯一目标是在两个堆栈中使用taginfolist observableCollection,但我不确定该怎么做。

谢谢!

I am currently working with a Xamarin app for reading RFID temperature tags and updating their values in real time. The current setup uses two Horizontal StackLayouts, one with a ListView showing a list of tags and their values, and the other with a Grid of Images of the human body that I wish to display the values on as well (in specific places).

In the ListView side, I can successfully call an object called TagInfoList, which is an ObservableCollection in the Class I call from the BasePage initialization. However, on the Grid side, I've tried multiple methods of using the TagInfoList, but it does not work. I've tried BindableLayouts, DataTemplates + ViewCells, and none allow me to get TagInfoList usable within my second StackLayout.

Here is the XAML code for the two horizontal StackLayouts:

<StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">
          <ListView x:Name="liewViewTagData" ItemsSource="{Binding TagInfoList}" SelectedItem="{Binding objItemSelected, Mode=TwoWay}">
            <ListView.Header>
              <StackLayout BackgroundColor="#cccccc">
                <Grid>
                  <!-- Grid + Label code irrelevant to my issue-->
                </Grid>
              </StackLayout>
            </ListView.Header>

            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                  <StackLayout Orientation="Vertical">
                    <Grid>
                      <!-- Grid + Label code irrelevant to my issue-->
                    </Grid>
                  </StackLayout>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
          </ListView>
        </StackLayout> <!-- RFID Tag Section -->

        <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand"> <!-- Body Model Section -->
          <!-- HERE: WHAT TO PUT FOR TagInfoList TO BE USABLE? -->
          <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" WidthRequest="400" ColumnSpacing="0">
             <!-- Grid + Label + Images I want to use TagInfoList information in -->
          </Grid>
          <!-- HERE: WHAT TO PUT FOR TagInfoList TO BE USABLE? -->
        </StackLayout> <!-- Body Model Section -->
      </StackLayout>```

I've deleted the bulk of inside Grids since it's not relevant. TagInfoList is an ObservableCollection of a class which contains all the data I need (strings and ints). How do I utilize TagInfoList within the second StackLayout? If I do it the same method as the first StackLayout, I get an error that I've called TagInfoList twice (through the 'liewViewTagData' item). Here is that code in the .xaml.cs file:

liewViewTagData.ItemSelected += (sender, e) => {
                if (e.SelectedItem == null) return;     // Don't do anything if we just de-selected the row
                ((ListView)sender).SelectedItem = null; // De-select the row
            };

My sole goal is to use the TagInfoList ObservableCollection within both StackLayouts, but I'm not sure how to do that.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆光飞翔i 2025-01-25 12:12:03

如果我这样做的方法与第一个堆栈相同的方法,我会发现一个错误
我两次称之为taginfolist(通过“ liewviewtagdata”
项目)。

您可以以与第一个stacklayout相同的方式进行操作,并且可以将两个listViews的属性 x:name 更改为不同的name

您可以参考以下代码:

     <ScrollView Orientation="Horizontal">
    <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">

            <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand">
                <ListView  x:Name="liewViewTagData" RowHeight="60" ItemsSource="{ Binding TagInfoList}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>

                                <!--other code-->

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

            <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand">
                <ListView  x:Name="liewView2" RowHeight="60" ItemsSource="{ Binding TagInfoList}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>

                                <!--other code-->
                                
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </StackLayout>
    </ScrollView>

注意:

如果您的水平空间用完,我建议您在外层添加scrollview

If I do it the same method as the first StackLayout, I get an error
that I've called TagInfoList twice (through the 'liewViewTagData'
item).

You can do it in the same way as the first StackLayout.And you can change property x:Name of the two listviews to different Name.

You can refer to the following code:

     <ScrollView Orientation="Horizontal">
    <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand">

            <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand">
                <ListView  x:Name="liewViewTagData" RowHeight="60" ItemsSource="{ Binding TagInfoList}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>

                                <!--other code-->

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

            <StackLayout Orientation="Horizontal" HorizontalOptions="EndAndExpand">
                <ListView  x:Name="liewView2" RowHeight="60" ItemsSource="{ Binding TagInfoList}">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>

                                <!--other code-->
                                
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </StackLayout>
    </ScrollView>

Note:

If you run out of horizontal space, I suggest you add a ScrollView to the outer layer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文