Click here to Skip to main content
15,914,016 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Customize Scrollbar in wpf Pin
Richard Deeming7-Dec-17 8:30
mveRichard Deeming7-Dec-17 8:30 
GeneralIterating the cells of a gridview Pin
Member 83993636-Dec-17 12:49
Member 83993636-Dec-17 12:49 
GeneralRe: Iterating the cells of a gridview Pin
Gerry Schmitz6-Dec-17 16:53
mveGerry Schmitz6-Dec-17 16:53 
GeneralRe: Iterating the cells of a gridview Pin
Member 83993636-Dec-17 17:14
Member 83993636-Dec-17 17:14 
GeneralRe: Iterating the cells of a gridview Pin
Gerry Schmitz6-Dec-17 17:52
mveGerry Schmitz6-Dec-17 17:52 
GeneralRe: Iterating the cells of a gridview Pin
Member 83993636-Dec-17 18:01
Member 83993636-Dec-17 18:01 
GeneralRe: Iterating the cells of a gridview Pin
Gerry Schmitz6-Dec-17 18:13
mveGerry Schmitz6-Dec-17 18:13 
QuestionHow To Create This UI Pin
Kevin Marois1-Dec-17 5:17
professionalKevin Marois1-Dec-17 5:17 
AnswerRe: How To Create This UI Pin
Mycroft Holmes2-Dec-17 12:38
professionalMycroft Holmes2-Dec-17 12:38 
QuestionWPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 11:56
professionalKevin Marois30-Nov-17 11:56 
AnswerRe: WPF TreeView - Some Nodes Not Showing Pin
Mycroft Holmes30-Nov-17 12:14
professionalMycroft Holmes30-Nov-17 12:14 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Kevin Marois30-Nov-17 12:15
professionalKevin Marois30-Nov-17 12:15 
GeneralRe: WPF TreeView - Some Nodes Not Showing Pin
Mycroft Holmes30-Nov-17 12:41
professionalMycroft Holmes30-Nov-17 12:41 
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 

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.