Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want first to thank @Graeme_Grant for his great suppport in this article
https://www.codeproject.com/Questions/1250791/Load-usercontrol-by-reflection

I copied the code, added the reference and everything is working well !
I have an additional question. I want to have access to the selected listBox item (IView) to call a function inside.

What I have tried:

In MainView.xaml
<ListBox Grid.Row="1" Margin="10" Height="100" 
                 Name="PluginList"
                 ItemsSource="{Binding Plugins}" 
                 ItemTemplate="{StaticResource DetailsTemplate}"
                 SelectionChanged="ListBox_SelectionChanged"/>


in MainWindow.xaml.cs
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            IUIViewProviderBase selectedPlugin = PluginList.SelectedItem as IUIViewProviderBase;
            ExportFactory<IView> Iviews = selectedPlugin.Entry;
            IView item = Iviews.CreateExport().Value as IView;
            
        }


The problem is in the last line, CreateExport is creating a new instance of Iview...I don't reach the existing instance.
Posted
Updated 6-Jul-18 4:57am
v3
Comments
Patrice T 6-Jul-18 11:24am    
Bonjour Canard,
Pour toute question par rapport à un article, va en bas du dit article, il y a un mini forum ou tu peux poser tes questions directement à l'auteur.
canard29 6-Jul-18 11:27am    
Merci, je vais faire ça
Richard MacCutchan 6-Jul-18 12:02pm    
Please stick to English.
Graeme_Grant 6-Jul-18 12:33pm    
I replied to the question against my answer ... you can find my reply here: Load usercontrol by reflection[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900