Click here to Skip to main content
13,352,157 members (70,905 online)

Silverlight / WPF

 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 13:43
professionalKevin Marois30-Nov-17 13:43 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Mycroft Holmes30-Nov-17 20:41
professionalMycroft Holmes30-Nov-17 20:41 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 14:00
professionalKevin Marois30-Nov-17 14:00 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 13:38
professionalKevin Marois30-Nov-17 13:38 
QuestionMahApps Pin
Kevin Marois14-Nov-17 8:54
professionalKevin Marois14-Nov-17 8:54 
AnswerRe: MahApps Pin
Pete O'Hanlon14-Nov-17 11:32
protectorPete O'Hanlon14-Nov-17 11:32 
QuestionMEF ImportingConstructor - How do we pass different concrete class if accepting parameter is interface type Pin
Ashfaque Hussain6-Nov-17 3:40
memberAshfaque Hussain6-Nov-17 3:40 
AnswerRe: MEF ImportingConstructor - How do we pass different concrete class if accepting parameter is interface type Pin
Richard Deeming6-Nov-17 4:20
mvpRichard Deeming6-Nov-17 4:20 
What you've got there won't work. The contract names on the two exports don't match the default contract name on the import, so there's no match.

If you know which class you want to import at compile-time, then you can use the [Import] attribute to pick the right one:
[ImportingConstructor]
public MyViewModel([Import("ReadSQLData")] IProcessData processData)

If you don't know which one you want to use until runtime, you'll need to write some code to pick the right export. For example, you could use a combination of [ImportMany] and export metadata:
Metadata and Metadata Views | Attributed Programming Model Overview (MEF) | Microsoft Docs[^]
public interface IProcessDataMetadata
{
    string Name { get; }
}

[Export(typeof(IProcessData)), ExportMetadata("Name", "ReadSerialData")]
public class ReadSerialData : IProcessData { ... }

[Export(typeof(IProcessData)), ExportMetadata("Name", "ReadSQLData")]
public class ReadSQLData : IProcessData { ... }


public interface IMyViewModelFactory
{
    MyViewModel Create(string processorName);
}

[Export(typeof(IMyViewModelFactory))]
public class MyViewModelFactory : IMyViewModelFactory
{
    [ImportingConstructor]
    public MyViewModelFactory([ImportMany] IEnumerable<Lazy<IProcessData, IProcessDataMetadata>> processors)
    {
        Processors = processors.ToList();
    }
    
    public IReadOnlyCollection<Lazy<IProcessData, IProcessDataMetadata>> Processors { get; }
    
    public MyViewModel Create(string processorName)
    {
        Lazy<IProcessData, IProcessDataMetadata> processor = Processors.FirstOrDefault(p => p.Metadata.Name == processorName);
        if (processor == null) throw new ArgumentException($"Unknown processor '{processorName}'.", nameof(processorName));
        
        IProcessData processData = processor.Value;
        return new MyViewModel(processData);
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


QuestionWPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Member 1347601722-Oct-17 22:18
memberMember 1347601722-Oct-17 22:18 
AnswerRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Gerry Schmitz23-Oct-17 20:13
memberGerry Schmitz23-Oct-17 20:13 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Antoon Verroken26-Oct-17 2:26
memberAntoon Verroken26-Oct-17 2:26 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Gerry Schmitz26-Oct-17 5:09
memberGerry Schmitz26-Oct-17 5:09 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Antoon Verroken26-Oct-17 8:24
memberAntoon Verroken26-Oct-17 8:24 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Gerry Schmitz26-Oct-17 9:03
memberGerry Schmitz26-Oct-17 9:03 
QuestionHave Model Class Notify ViewModel Pin
Kevin Marois17-Oct-17 8:56
professionalKevin Marois17-Oct-17 8:56 
AnswerRe: Have Model Class Notify ViewModel Pin
Pete O'Hanlon17-Oct-17 9:51
protectorPete O'Hanlon17-Oct-17 9:51 
GeneralRe: Have Model Class Notify ViewModel Pin
Kevin Marois17-Oct-17 11:17
professionalKevin Marois17-Oct-17 11:17 
GeneralRe: Have Model Class Notify ViewModel Pin
Pete O'Hanlon17-Oct-17 11:44
protectorPete O'Hanlon17-Oct-17 11:44 
QuestionDatabind to a ListView or TreeView with an Observable Collection with several array properties Pin
Member 134501316-Oct-17 8:23
memberMember 134501316-Oct-17 8:23 
AnswerRe: Databind to a ListView or TreeView with an Observable Collection with several array properties Pin
Gerry Schmitz7-Oct-17 8:13
memberGerry Schmitz7-Oct-17 8:13 
AnswerRe: Databind to a ListView or TreeView with an Observable Collection with several array properties Pin
Mycroft Holmes7-Oct-17 16:07
professionalMycroft Holmes7-Oct-17 16:07 
QuestionGroup Box Visibility Pin
Mycroft Holmes3-Oct-17 22:50
professionalMycroft Holmes3-Oct-17 22:50 
AnswerRe: Group Box Visibility Pin
Gerry Schmitz4-Oct-17 7:29
memberGerry Schmitz4-Oct-17 7:29 
GeneralRe: Group Box Visibility Pin
Mycroft Holmes4-Oct-17 14:18
professionalMycroft Holmes4-Oct-17 14:18 
SuggestionRe: Group Box Visibility Pin
Richard Deeming4-Oct-17 10:21
mvpRichard Deeming4-Oct-17 10:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 20 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid