フォームの下部に一連のフィールドとページング ボタンがあるデータ フォームを作成しようとしています。
Paging を、First、Previous、Next、Last というラベルの Item 1 of n の個別のコントロールにしたいと考えています。
このページング コントロールは、ユーザーが前のレコード間を行き来できるようにするために、任意のデータ入力フォームで使用されます。たとえば、Orders、Invoices、Payments はデータ フォームです。ユーザーが注文を選択すると、新しい注文フォームが表示されます。また、前のレコードに移動するためのページング ボタンもあります。
PagingItems の依存関係プロパティを持つ DataPager という名前の UserControl を作成しました。アイテムのリスト (注文、請求書、支払い) を渡すことができるように、この依存関係プロパティをジェネリックにする必要があります。
このために私がしたこと: ユーザー コントロールにリストします。これをページングする必要があるフォームにバインドしてみました。
public List<object> Items
{
get { return (List<object>)GetValue(ItemsProperty); }
set { SetValue(ItemsProperty, value); }
}
// Using a DependencyProperty as the backing store for Items. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ItemsProperty =
DependencyProperty.Register("Items", typeof(List<object>), typeof(DataPager), new UIPropertyMetadata(null, LoadItems));
private static void LoadItems(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
DataPager thisControl = (DataPager)obj;
thisControl.RefreshItems();
}
コントロールとバインドを使用するページで次のエラーが発生します。
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Collections.Generic.List`1[PagingSample.Order]' and 'System.Collections.Generic.List`1[System.Object]'. Consider using Converter property of Binding. BindingExpression:Path=Orders; DataItem='MainViewModel' (HashCode=26754911); target element is 'DataPager' (Name='dataPager1'); target property is 'Items' (type 'List`1')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='System.Collections.Generic.List`1[PagingSample.Order]' BindingExpression:Path=Orders; DataItem='MainViewModel' (HashCode=26754911); target element is 'DataPager' (Name='dataPager1'); target property is 'Items' (type 'List`1')
DataPager コントロールの item プロパティをジェネリックにする方法がわかりません。親コントロールに CurrentItem を表示するように指示する方法はまだわかりません。
しかし、最初のハードルをクリアしたかった。どんな助けでも感謝します。