私はすべての場所を読んでいます。そのバインディングはWPF to Interfacesで実行できますが、実際には何かの牽引力を得ています。私はあなたが私のコードを準備するのに役立つなら、EFコアも使用しています。 ComboBoxはデータで塗りつぶされ、データのバインドは機能しますが、SelectedItem
はバインドに失敗し、選択した項目内のテキストは空白になります。ComboBox SelectedItemのためのWPFのバインドインターフェイス
私は次のことを理解していない、インターフェイスを実装するオブジェクトにバインドします。
コンボボックスのためのXAML:
<ComboBox Height="23" x:Name="cbJumpList" Width="177" Margin="2" HorizontalAlignment="Left"
IsEditable="False"
DisplayMemberPath="Name"
SelectedItem="{Binding Path=(model:IData.SelectedJumpList), Mode=TwoWay}"
/>
MainWindow.xaml.cs:
protected IData DB { get; private set; }
public MainWindow()
{
InitializeComponent();
DB = new Data.DataSQLite(true);
DB.Bind_JumpLists_ItemsSource(cbJumpList);
}
IData.cs:
public interface IData : IDisposable, INotifyPropertyChanged
{
void Bind_JumpLists_ItemsSource(ItemsControl control);
IJumpList First_JumpList();
IJumpList SelectedJumpList { get; set; } // TwoWay Binding
}
IJumpList.cs
は、次に実装されたオブジェクト(Data.DataSQLite)内:
public void Bind_JumpLists_ItemsSource(ItemsControl control)
{
control.ItemsSource = null;
db.JumpLists.ToList();
control.ItemsSource = db.JumpLists.Local;
control.Tag = db.JumpLists.Local;
SelectedJumpList = db.JumpLists.FirstOrDefault();
}
public IJumpList SelectedJumpList
{
get { return _SelectedJumpList; }
set
{
_SelectedJumpList = value;
NotifyPropertyChanged();
}
}
IJumpList _SelectedJumpList;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
私はPropertyChangedイベントがnullのまま、追加する必要があります。
は、ToListメソッド() ''から返されたプロパティをのSelectedItemするリストをバインドしようとすると? 'IJumpList'の中身は何ですか? –
@SivaGopalいいえ、ToListは別のバインディングで使用されている 'Items.Local'プロパティを別の場所で更新しています。私はそれが混乱の原因になるかもしれないと思った、私はそれを編集します。 –