Click here to Skip to main content
15,884,388 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 12:43
professionalKevin Marois30-Nov-17 12:43 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Mycroft Holmes30-Nov-17 19:41
professionalMycroft Holmes30-Nov-17 19:41 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 13:00
professionalKevin Marois30-Nov-17 13:00 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 12:38
professionalKevin Marois30-Nov-17 12:38 
QuestionMahApps Pin
Kevin Marois14-Nov-17 7:54
professionalKevin Marois14-Nov-17 7:54 
AnswerRe: MahApps Pin
Pete O'Hanlon14-Nov-17 10:32
mvePete O'Hanlon14-Nov-17 10:32 
QuestionMEF ImportingConstructor - How do we pass different concrete class if accepting parameter is interface type Pin
Ashfaque Hussain6-Nov-17 2:40
Ashfaque Hussain6-Nov-17 2:40 
AnswerRe: MEF ImportingConstructor - How do we pass different concrete class if accepting parameter is interface type Pin
Richard Deeming6-Nov-17 3:20
mveRichard Deeming6-Nov-17 3: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:
C#
[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[^]
C#
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 21:18
Member 1347601722-Oct-17 21:18 
AnswerRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Gerry Schmitz23-Oct-17 19:13
mveGerry Schmitz23-Oct-17 19:13 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Antoon Verroken26-Oct-17 1:26
Antoon Verroken26-Oct-17 1:26 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Gerry Schmitz26-Oct-17 4:09
mveGerry Schmitz26-Oct-17 4:09 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Antoon Verroken26-Oct-17 7:24
Antoon Verroken26-Oct-17 7:24 
GeneralRe: WPF, DevExpress: Stop dxn:NavBarControl recreates it's children Pin
Gerry Schmitz26-Oct-17 8:03
mveGerry Schmitz26-Oct-17 8:03 
QuestionHave Model Class Notify ViewModel Pin
Kevin Marois17-Oct-17 7:56
professionalKevin Marois17-Oct-17 7:56 
AnswerRe: Have Model Class Notify ViewModel Pin
Pete O'Hanlon17-Oct-17 8:51
mvePete O'Hanlon17-Oct-17 8:51 
GeneralRe: Have Model Class Notify ViewModel Pin
Kevin Marois17-Oct-17 10:17
professionalKevin Marois17-Oct-17 10:17 
GeneralRe: Have Model Class Notify ViewModel Pin
Pete O'Hanlon17-Oct-17 10:44
mvePete O'Hanlon17-Oct-17 10:44 
QuestionDatabind to a ListView or TreeView with an Observable Collection with several array properties Pin
Member 134501316-Oct-17 7:23
Member 134501316-Oct-17 7:23 
AnswerRe: Databind to a ListView or TreeView with an Observable Collection with several array properties Pin
Gerry Schmitz7-Oct-17 7:13
mveGerry Schmitz7-Oct-17 7:13 
AnswerRe: Databind to a ListView or TreeView with an Observable Collection with several array properties Pin
Mycroft Holmes7-Oct-17 15:07
professionalMycroft Holmes7-Oct-17 15:07 
QuestionGroup Box Visibility Pin
Mycroft Holmes3-Oct-17 21:50
professionalMycroft Holmes3-Oct-17 21:50 
AnswerRe: Group Box Visibility Pin
Gerry Schmitz4-Oct-17 6:29
mveGerry Schmitz4-Oct-17 6:29 
GeneralRe: Group Box Visibility Pin
Mycroft Holmes4-Oct-17 13:18
professionalMycroft Holmes4-Oct-17 13:18 
SuggestionRe: Group Box Visibility Pin
Richard Deeming4-Oct-17 9:21
mveRichard Deeming4-Oct-17 9: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.