-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from macadmins/dev
v1.4.0
- Loading branch information
Showing
26 changed files
with
370 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.ComponentModel; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.Templates; | ||
|
||
namespace SupportCompanion.Common; | ||
|
||
public class ViewLocator : IDataTemplate | ||
{ | ||
private readonly Dictionary<object, Control> _controlCache = new(); | ||
|
||
public Control Build(object? data) | ||
{ | ||
if (data is null) | ||
return new TextBlock { Text = "Data is null." }; | ||
|
||
var fullName = data.GetType().FullName; | ||
|
||
if (string.IsNullOrWhiteSpace(fullName)) | ||
return new TextBlock { Text = "Type has no name, or name is empty." }; | ||
|
||
var name = fullName.Replace("ViewModel", "View"); | ||
var type = Type.GetType(name); | ||
if (type is null) | ||
return new TextBlock { Text = $"No View For {name}." }; | ||
|
||
if (!_controlCache.TryGetValue(data, out var res)) | ||
{ | ||
res ??= (Control)Activator.CreateInstance(type)!; | ||
_controlCache[data] = res; | ||
} | ||
|
||
res.DataContext = data; | ||
return res; | ||
} | ||
|
||
public bool Match(object? data) | ||
{ | ||
return data is INotifyPropertyChanged; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.