ListViewで使用するはずのカスタムViewCellを作成しました 同じコードはAndroidでは動作しますが、UWPでは動作しません(Windows PhoneとWindowsデスクトップの両方)。Xamarin.UWPカスタムViewCellにバインドに関する問題があります
プロジェクトはXamarinフォームです。
私は私のListViewコントロール内で使用する場合...私は空白のセルを見ることができます。
<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AAA.Extensions.AttributeViewCell"
Tapped="AttributeViewCell_OnTapped"
>
<Grid
x:Name="AttributeGrid"
>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackLayout
Grid.Column="0"
>
<Label
Text="{Binding Code}"
TextColor="#000000"
/>
<Label
Text="{Binding Description}"
TextColor="#000000"
/>
</StackLayout>
<StackLayout
Grid.Column="1"
x:Name="DynamicContentStackLayout"
>
</StackLayout>
</Grid>
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class AttributeViewCell : ViewCell
{
#region Bindable Properties
public static readonly BindableProperty CodeProperty = BindableProperty.Create(nameof(Code),typeof(string),typeof(AttributeViewCell), defaultBindingMode:BindingMode.TwoWay);
public static readonly BindableProperty DescriptionProperty = BindableProperty.Create(nameof(Description), typeof(string), typeof(AttributeViewCell), defaultBindingMode:BindingMode.TwoWay);
#endregion
#region Properties
/// <summary>
/// Attribute Code
/// </summary>
public string Code
{
get => (string) GetValue(CodeProperty);
set => SetValue(CodeProperty,value);
}
/// <summary>
/// Attribute's description
/// </summary>
public string Description
{
get => (string) GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}
#endregion
public AttributeViewCell()
{
InitializeComponent();
this.BindingContext = this;
}
private void AttributeViewCell_OnTapped(object sender, EventArgs e)
{
// I CAN SEE BINDINGS here...
}
}
の背後にある私のコードバインディングは、以下の
public class Attribute
{
public string Code { get; set; }
public string Description { get; set; }
}
VM 公共CLAなどのViewModelに POCOの外観全体で行われていますss ProductDetailsPageViewModel:BaseViewModel { #regionフィールド private readonly AnonymousCheckerService _anonymousCheckerService; プライベートList _attributes;私はviewcell上のタップイベントを添付しました
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:extensions="clr-namespace:AnonymousCheckerApp.Extensions"
x:Class="AnonymousCheckerApp.Views.ProductDetailsPage">
<StackLayout>
<ListView
ItemsSource="{Binding Attributes}"
>
<ListView.ItemTemplate>
<DataTemplate>
<extensions:AttributeViewCell
Code="{Binding Code}"
Description="{Binding Description}"
AttributeDetails="{Binding AttributeDetails}"
/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
and it's codebehind
public ProductDetailsPage()
{
var vm = new ProductDetailsPageViewModel();
this.BindingContext = vm;
InitializeComponent();
}
#endregion
#region Properties
public List<Attribute> Attributes
{
get => _attributes;
set
{
_attributes = value;
OnPropertyChanged();
}
}
#endregion
//basic ctor
public ProductDetailsPageViewModel()
{
_aaa= new aaa();
Attributes = _aaa.GetInfo("123").Attributes;
}
}
そして最後に、リストビュー...私は束縛を見ることができます...
編集1
私は通信しましたGrid
要素内にスタックされた要素のバインドに問題がある他の開発者が見つかりました... まだ動作しておらず、奇妙なのはXAML要素を適切に "解析"することですが、バインディングを行うことができません....私は間違って何をしていますか?
これは、私はあなたのコードをテストして問題を再現しているAndroidの
それは多分、テキストが何らかの理由で白で、別の問題ではないですか? 'TextColor'をRedに設定するか、それを除外するために何かを設定することができます:) –
Text = {Binding}をレンダリングするharcoded値に置き換えても、メインスレッドを更新しました。 。 – ExtremeSwat