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
using KsWare.Presentation.ViewModelFramework; | |
namespace MyProject { | |
public class XyzVM : ObjectVM { | |
public XxxVM () { | |
RegisterChildren(()=>this); | |
} | |
} |
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
using KsWare.Presentation.ViewModelFramework; | |
namespace MyProject { | |
public class XyzDataVM : DataVM<XyzData> { | |
public XxxVM () { | |
RegisterChildren(()=>this); | |
Fields[nameof(Name)].ValueChangedEvent.add(() => Data.Name = Name); // save changes immediately to data model |
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
<Style> | |
<d:Style.DataContext> | |
<x:Type Type="local:MyTreeItem" /> | |
</d:Style.DataContext> | |
<!--usual setters, triggers, etc.--> | |
</Style> |
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
public static T ReadBaml<T>(Stream stream) { | |
var bamlReader = new Baml2006Reader(stream); | |
var writer = new XamlObjectWriter(bamlReader.SchemaContext); | |
while (bamlReader.Read()) writer.WriteNode(bamlReader); | |
return (T)writer.Result; | |
} |
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
using System; | |
using System.Collections.Generic; | |
using System.Windows; | |
using System.Windows.Controls.Primitives; | |
using System.Windows.Markup.Primitives; | |
using System.Windows.Media; | |
public static class DependencyObjectExtensions | |
{ | |
public static List<DependencyProperty> GetDependencyProperties(this DependencyObject element) |
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
public sealed class GuidSemaphoreSlim : IDisposable | |
{ | |
private static readonly Dictionary<Guid,SemaphoreSlim> Handles=new Dictionary<Guid, SemaphoreSlim>(); | |
private readonly Guid _guid; | |
private readonly SemaphoreSlim _semaphore; | |
/// <summary> | |
/// Usage: using(await GuidSemaphoreSlim.WaitAsync(myGuid)) {...} | |
/// </summary> | |
public static async Task<IDisposable> WaitAsync(Guid guid) |
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
public struct Result<TValue> | |
{ | |
internal Result(TValue value, bool success, object failureInfo) | |
{ | |
Value = value; | |
Success = success; | |
FailureInfo = failureInfo; | |
} | |
public TValue Value { get; private set; } |
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
public static class WaitHandleAsyncExtension | |
{ | |
public static async Task<bool> WaitOneAsync(this WaitHandle handle, int millisecondsTimeout, CancellationToken cancellationToken) | |
{ | |
RegisteredWaitHandle registeredHandle = null; | |
var tokenRegistration = new CancellationTokenRegistration(); | |
try | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
registeredHandle = ThreadPool.RegisterWaitForSingleObject( |
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
public static class AsyncHelpers | |
{ | |
/// <summary> | |
/// Execute's an async Task<T> method which has a void return value synchronously | |
/// </summary> | |
/// <param name="task">Task<T> method to execute</param> | |
public static void RunSync(Func<Task> task) | |
{ | |
var oldContext = SynchronizationContext.Current; | |
var synch = new ExclusiveSynchronizationContext(); |
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
public static string GenerateFullTypeName(Type type) | |
{ | |
var retType = new StringBuilder(); | |
if (type.IsGenericType) | |
{ | |
var parentType = type.FullName.Split('`'); | |
var arguments = type.GetGenericArguments(); | |
var argList = new StringBuilder(); |
OlderNewer