我正在使用WinForms應用程序中的一些WPF互操作性。我有以下設置。WinForm中的Interop WPF,如何處理來自WPF控件的事件
- 的WinForms用戶控件WFControl
- WPF用戶控件GalleryControl
- 列表框GalleryItems
- 列表框的ItemTemplate GalleryItem
- 列表框GalleryItems
- WPF用戶控件GalleryControl
Winforms託管GalleryControl,它具有GalleryItems(ListBox),它具有GalleryItem的ItemTemplate。
現在在WFControl中,我想看看GalleryItems是否有SelectionChanged
事件觸發。
我目前的嘗試已經嘗試:
處理SelectionChanged事件中GalleryControl並將它提高我的WinForms可以讀取一個單獨的公共事件,但因爲它是我不能處理這樣的事件不是路由事件。如果我能弄清楚如何處理這個問題,這將起作用。適用代碼:
public event ClaimGallery SelectedClaimChanged; public ViewModels.InsuranceClaimViewModel ClaimViewModel { get; set; } public int SelectedClaimID { get { return ((Models.InsuranceClaim) ClaimList.SelectedItem).ID; } } public ClaimGallery() { InitializeComponent(); ClaimViewModel = new ViewModels.InsuranceClaimViewModel(); DataContext = ClaimViewModel; ClaimList.ItemsSource = ClaimViewModel.InsuranceClaims; ClaimList.SelectionChanged += ClaimSelectionChanged; } private void ClaimSelectionChanged(object sender, EventArgs e) { //This is the part that doesn't work ClaimList.RaiseEvent(new RoutedEventArgs(SelectedClaimChanged, this)); }
我也看到了,我可能會發現通過某種控制樹瀏覽訂閱的WFControl實際事件列表框,但我似乎無法弄清楚如何做這在互相控制。
我無法到達WinForms中的GalleryItems.SelectionChanged – msarchet 2011-02-11 16:55:17