我目前正在使用 Xamarin 應用程式來讀取 RFID 溫度標簽并實時更新它們的值。當前設定使用兩個 Horizo??ntal StackLayouts,一個帶有 ListView 顯示標簽及其值的串列,另一個帶有我希望在其上顯示值的人體影像網格(在特定位置)。
在 ListView 端,我可以成功呼叫一個名為 TagInfoList 的物件,它是我從 BasePage 初始化呼叫的 Class 中的一個 ObservableCollection。但是,在網格方面,我嘗試了多種使用 TagInfoList 的方法,但它不起作用。我已經嘗試過 BindableLayouts、DataTemplates ViewCells,但沒有一個允許我在第二個 StackLayout 中使用 TagInfoList。
這是兩個水平 StackLayouts 的 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 是一個包含我需要的所有資料(字串和整數)的類的 ObservableCollection。如何在第二個 StackLayout 中使用 TagInfoList?如果我以與第一個 StackLayout 相同的方法執行此操作,則會收到一個錯誤,我已呼叫 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
};
我的唯一目標是在兩個 StackLayouts 中使用 TagInfoList ObservableCollection,但我不知道該怎么做。
謝謝!
uj5u.com熱心網友回復:
如果我以與第一個 StackLayout 相同的方法執行此操作,則會收到一個錯誤,我已呼叫 TagInfoList 兩次(通過“liewViewTagData”項)。
您可以按照與第一個相同的方式進行操作StackLayout。您可以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在外層添加一個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/461948.html
標籤:xml xamarin xamarin.forms uwp-xml xamarin.uwp
上一篇:將int變數系結為樣式中的值
