ListViewでTextCellをクリックすると、その行が強調表示されます。コードでTextCellを選択しても行がハイライト表示されない
ただし、プログラムで行/テキストセルを選択すると、その行はハイライト表示されません。
したがって、行をタップして選択を変更しない限り、現在選択されているListViewの値をユーザーに示すことはできません。
これはバグですか、機能が欠けているのでしょうか、コードを使ってどのように強調表示できますか?
サンプルコードは以下に添付されています。あなたは、これはそれがAndroidとiOS上で正常に動作方法を見て、そのプラットフォーム上で、具体的バグのように見えるUWPフォームアプリでテストされているコメントで述べたように
using MyApp.Model;
using System.Collections.Generic;
using Xamarin.Forms;
namespace MyApp
{
public class IntSelector : ContentPage
{
private ListView m_ListView;
public IntSelector(int uSelectedInt)
{
DataTemplate nTemplate = new DataTemplate(typeof(TextCell));
// We can set data bindings to our supplied objects.
nTemplate.SetBinding(TextCell.TextProperty, "String");
nTemplate.SetBinding(TextCell.DetailProperty, "Int");
List<clsStringInt> nList = new List<clsStringInt>();
clsStringInt nItem1 = new clsStringInt { String = "German", Int = 1031 };
clsStringInt nItem2 = new clsStringInt { String = "English", Int = 1033 };
clsStringInt nItem3 = new clsStringInt { String = "Spanish", Int = 1034 };
nList.Add(nItem1);
nList.Add(nItem2);
nList.Add(nItem3);
m_ListView = new ListView();
m_ListView.ItemTemplate = nTemplate;
m_ListView.ItemsSource = nList;
m_ListView.ItemSelected += this.OnSelection;
m_ListView.SelectedItem = nItem2;//this triggers the "OnSelection" event, so it works
nItem2.String = "->> " + nItem2.String; //the item's new string is display in the ListView, so that works as well
//what DOESN'T work is the highliting
this.Content = m_ListView;
}
void OnSelection(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem == null)
{
return; //ItemSelected is called on deselection, which results in SelectedItem being set to null
}
clsStringInt n = (clsStringInt)e.SelectedItem;
string sSelectedIntAsString = n.Int.ToString();
DisplayAlert("Item Selected", sSelectedIntAsString, "Ok");
}
}
}
namespace MyApp.Model
{
public class clsStringInt
{
public string String { get; set; }
public int Int { get; set; }
}
}
使用しているフォームのバージョンがあり、行がハイライト表示されていないコードで再作成していないため、ページに.xamlコードがあります。 – Nick
いいえ、それは普通のC#です.XAMLは必要ありません。 Xamarin.Forms 2.4.0.74863 – tmighty
@ニック私は2.5.0.91635にアップデートしました。これは同じ動作です。 – tmighty