Click here to Skip to main content
15,843,623 members
Home / Discussions / WPF
   

WPF

 
SuggestionRe: Code Behind Data Grid Style Issue Pin
Richard Deeming6-Apr-22 23:37
mveRichard Deeming6-Apr-22 23:37 
GeneralRe: Code Behind Data Grid Style Issue Pin
Kevin Marois7-Apr-22 6:25
professionalKevin Marois7-Apr-22 6:25 
AnswerRe: Code Behind Data Grid Style Issue Pin
Gerry Schmitz7-Apr-22 7:42
mveGerry Schmitz7-Apr-22 7:42 
GeneralRe: Code Behind Data Grid Style Issue Pin
Kevin Marois7-Apr-22 15:34
professionalKevin Marois7-Apr-22 15:34 
Questiontrack active split view Pin
Super Lloyd5-Apr-22 14:47
Super Lloyd5-Apr-22 14:47 
QuestionViewModel Locator Pin
Kevin Marois5-Apr-22 8:48
professionalKevin Marois5-Apr-22 8:48 
AnswerRe: ViewModel Locator Pin
Super Lloyd5-Apr-22 14:56
Super Lloyd5-Apr-22 14:56 
SuggestionRe: ViewModel Locator Pin
Richard Deeming5-Apr-22 22:27
mveRichard Deeming5-Apr-22 22:27 
Kevin Marois wrote:
C#
public object Get<T>()
{
    if (_storage.ContainsKey(typeof(T)))
    {
        return _storage.FirstOrDefault(x => x.Key == typeof(T)).Value;
    }
    else
    {
        throw new Exception($"The requested view '{typeof(T)}' is not registered");
    }
}
That's a very strange way of using a dictionary. The alternative is simpler and significantly more efficient:
C#
public object Get<T>()
{
    if (!_storage.TryGetValue(typeof(T), out var result)) return result;
    throw new ArgumentException($"The requested view '{typeof(T)}' is not registered");
}

And the method doesn't have to be generic - you can have a non-generic overload as well:
C#
public object Get(Type viewType)
{
    if (viewType is null) throw new ArgumentNullException(nameof(viewType));
    if (!_storage.TryGetValue(viewType, out var result)) return result;
    throw new ArgumentException($"The requested view '{viewType}' is not registered", nameof(viewType));
}




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

AnswerRe: ViewModel Locator Pin
Richard Deeming5-Apr-22 22:42
mveRichard Deeming5-Apr-22 22:42 
GeneralRe: ViewModel Locator Pin
Kevin Marois6-Apr-22 7:11
professionalKevin Marois6-Apr-22 7:11 
QuestionIs it possible to share SQL Server database between WPF application and Ionic application Pin
Alex Dunlop28-Mar-22 8:03
Alex Dunlop28-Mar-22 8:03 
AnswerRe: Is it possible to share SQL Server database between WPF application and Ionic application Pin
Dave Kreskowiak28-Mar-22 11:11
mveDave Kreskowiak28-Mar-22 11:11 
AnswerRe: Is it possible to share SQL Server database between WPF application and Ionic application Pin
Mycroft Holmes28-Mar-22 13:28
professionalMycroft Holmes28-Mar-22 13:28 
QuestionDataTrigger not working Pin
Kevin Marois7-Mar-22 9:35
professionalKevin Marois7-Mar-22 9:35 
AnswerRe: DataTrigger not working Pin
Dave Kreskowiak7-Mar-22 11:27
mveDave Kreskowiak7-Mar-22 11:27 
AnswerRe: DataTrigger not working Pin
Richard Deeming7-Mar-22 22:15
mveRichard Deeming7-Mar-22 22:15 
GeneralRe: DataTrigger not working Pin
Kevin Marois8-Mar-22 6:32
professionalKevin Marois8-Mar-22 6:32 
QuestionQuestion about NotifyCollectionChangedEventArgs Pin
Super Lloyd1-Mar-22 13:12
Super Lloyd1-Mar-22 13:12 
AnswerRe: Question about NotifyCollectionChangedEventArgs Pin
Richard Deeming1-Mar-22 22:42
mveRichard Deeming1-Mar-22 22:42 
QuestionAnimation on DataGridRow jumps to wrong row when scrolling Pin
Mc_Topaz28-Feb-22 0:31
Mc_Topaz28-Feb-22 0:31 
AnswerRe: Animation on DataGridRow jumps to wrong row when scrolling Pin
Gerry Schmitz28-Feb-22 9:11
mveGerry Schmitz28-Feb-22 9:11 
GeneralRe: Animation on DataGridRow jumps to wrong row when scrolling Pin
Mc_Topaz28-Feb-22 21:28
Mc_Topaz28-Feb-22 21:28 
QuestionLabelprint on Thermotransfer Pin
Member 118002289-Feb-22 1:34
Member 118002289-Feb-22 1:34 
QuestionRe: Labelprint on Thermotransfer Pin
Eddy Vluggen9-Feb-22 4:13
professionalEddy Vluggen9-Feb-22 4:13 
QuestionWPF c# onStartUp() view model problem with multiple data inputs Pin
StealthRT5-Feb-22 8:31
StealthRT5-Feb-22 8:31 

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.