-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Imported Prism.Avalonia v9.0.401.11000-pre raw files (unconverted)
- Loading branch information
1 parent
d8b81f8
commit 015a067
Showing
192 changed files
with
23,192 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"solution": { | ||
"path": "Prism.Avalonia.sln", | ||
"projects": [ | ||
"src\\Containers\\Prism.DryIoc.Shared\\Prism.DryIoc.Shared.shproj", | ||
"src\\Avalonia\\Prism.Avalonia\\Prism.Avalonia.csproj", | ||
"src\\Avalonia\\Prism.DryIoc.Avalonia\\Prism.DryIoc.Avalonia.csproj", | ||
"tests\\Avalonia\\Prism.Avalonia.Tests\\Prism.Avalonia.Tests.csproj", | ||
"tests\\Avalonia\\Prism.Container.Avalonia.Shared\\Prism.Container.Avalonia.Shared.shproj", | ||
"tests\\Avalonia\\Prism.DryIoc.Avalonia.Tests\\Prism.DryIoc.Avalonia.Tests.csproj", | ||
"tests\\Avalonia\\Prism.IocContainer.Avalonia.Tests.Support\\Prism.IocContainer.Avalonia.Tests.Support.csproj" | ||
] | ||
} | ||
} |
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,80 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using Avalonia.Controls; | ||
using Prism.Mvvm; | ||
|
||
namespace Prism.Common | ||
{ | ||
/// <summary> | ||
/// Helper class for MVVM. | ||
/// </summary> | ||
public static class MvvmHelpers | ||
{ | ||
/// <summary> | ||
/// Sets the AutoWireViewModel property to true for the <paramref name="viewOrViewModel"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// The AutoWireViewModel property will only be set to true if the view | ||
/// is a <see cref="FrameworkElement"/>, the DataContext of the view is null, and | ||
/// the AutoWireViewModel property of the view is null. | ||
/// </remarks> | ||
/// <param name="viewOrViewModel">The View or ViewModel.</param> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
internal static void AutowireViewModel(object viewOrViewModel) | ||
{ | ||
if (viewOrViewModel is Control view && | ||
view.DataContext is null && | ||
ViewModelLocator.GetAutoWireViewModel(view) is null) | ||
{ | ||
ViewModelLocator.SetAutoWireViewModel(view, true); | ||
} | ||
} | ||
|
||
////#endif | ||
|
||
/// <summary> | ||
/// Perform an <see cref="Action{T}"/> on a view and ViewModel. | ||
/// </summary> | ||
/// <remarks> | ||
/// The action will be performed on the view and its ViewModel if they implement <typeparamref name="T"/>. | ||
/// </remarks> | ||
/// <typeparam name="T">The <see cref="Action{T}"/> parameter type.</typeparam> | ||
/// <param name="view">The view to perform the <see cref="Action{T}"/> on.</param> | ||
/// <param name="action">The <see cref="Action{T}"/> to perform.</param> | ||
public static void ViewAndViewModelAction<T>(object view, Action<T> action) where T : class | ||
{ | ||
if (view is T viewAsT) | ||
action(viewAsT); | ||
|
||
if (view is Control element && element.DataContext is T viewModelAsT) | ||
{ | ||
action(viewModelAsT); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Get an implementer from a view or ViewModel. | ||
/// </summary> | ||
/// <remarks> | ||
/// If the view implements <typeparamref name="T"/> it will be returned. | ||
/// Otherwise if the view's <see cref="FrameworkElement.DataContext"/> implements <typeparamref name="T"/> it will be returned instead. | ||
/// </remarks> | ||
/// <typeparam name="T">The implementer type to get.</typeparam> | ||
/// <param name="view">The view to get <typeparamref name="T"/> from.</param> | ||
/// <returns>view or ViewModel as <typeparamref name="T"/>.</returns> | ||
public static T GetImplementerFromViewOrViewModel<T>(object view) where T : class | ||
{ | ||
if (view is T viewAsT) | ||
{ | ||
return viewAsT; | ||
} | ||
|
||
if (view is Control element && element.DataContext is T vmAsT) | ||
{ | ||
return vmAsT; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
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,57 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
|
||
namespace Prism.Common | ||
{ | ||
/// <summary> | ||
/// Class that wraps an object, so that other classes can notify for Change events. Typically, this class is set as | ||
/// a Dependency Property on AvaloniaObjects, and allows other classes to observe any changes in the Value. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class is required, because in Silverlight, it's not possible to receive Change notifications for Dependency properties that you do not own. | ||
/// </remarks> | ||
/// <typeparam name="T">The type of the property that's wrapped in the Observable object</typeparam> | ||
public class ObservableObject<T> : Control, INotifyPropertyChanged | ||
{ | ||
/// <summary> | ||
/// Identifies the Value property of the ObservableObject | ||
/// </summary> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1000:DoNotDeclareStaticMembersOnGenericTypes", Justification = "This is the pattern for WPF dependency properties")] | ||
public static readonly StyledProperty<T> ValueProperty = | ||
AvaloniaProperty.Register<Control, T>(name: nameof(Value)); | ||
|
||
//StyledProperty.Register("Value", typeof(T), typeof(ObservableObject<T>), new PropertyMetadata(ValueChangedCallback)); | ||
|
||
/// <summary> | ||
/// Event that gets invoked when the Value property changes. | ||
/// </summary> | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
/// <summary> | ||
/// The value that's wrapped inside the ObservableObject. | ||
/// </summary> | ||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] | ||
public T Value | ||
{ | ||
get { return (T)this.GetValue(ValueProperty); } | ||
set { this.SetValue(ValueProperty, value); } | ||
} | ||
|
||
private static void ValueChangedCallback(AvaloniaObject d, AvaloniaPropertyChangedEventArgs e) | ||
{ | ||
ObservableObject<T> thisInstance = ((ObservableObject<T>)d); | ||
PropertyChangedEventHandler eventHandler = thisInstance.PropertyChanged; | ||
if (eventHandler != null) | ||
{ | ||
eventHandler(thisInstance, new PropertyChangedEventArgs(nameof(Value))); | ||
} | ||
} | ||
|
||
static ObservableObject() | ||
{ | ||
ValueProperty.Changed.Subscribe(args => ValueChangedCallback(args?.Sender, args)); | ||
} | ||
} | ||
} |
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,76 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Styling; | ||
|
||
namespace Prism.Dialogs | ||
{ | ||
/// <summary> | ||
/// This class contains <see cref="IDialogWindow"/> attached properties. | ||
/// </summary> | ||
public class Dialog | ||
{ | ||
/// <summary>Identifies the WindowStyle attached property.</summary> | ||
/// <remarks>This attached property is used to specify the style of a <see cref="IDialogWindow"/>.</remarks> | ||
public static readonly AvaloniaProperty WindowStyleProperty = | ||
AvaloniaProperty.RegisterAttached<AvaloniaObject, Style>("WindowStyle", typeof(Dialog)); | ||
|
||
/// <summary>Identifies the WindowStartupLocation attached property.</summary> | ||
/// <remarks>This attached property is used to specify the startup location of a <see cref="IDialogWindow"/>.</remarks> | ||
public static readonly AvaloniaProperty WindowStartupLocationProperty = | ||
AvaloniaProperty.RegisterAttached<AvaloniaObject, WindowStartupLocation>( | ||
name: "WindowStartupLocation", | ||
ownerType: typeof(Dialog)); | ||
|
||
public Dialog() | ||
{ | ||
WindowStartupLocationProperty.Changed.Subscribe(args => OnWindowStartupLocationChanged(args?.Sender, args)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value for the <see cref="WindowStyleProperty"/> attached property. | ||
/// </summary> | ||
/// <param name="obj">The target element.</param> | ||
/// <returns>The <see cref="WindowStyleProperty"/> attached to the <paramref name="obj"/> element.</returns> | ||
public static Style GetWindowStyle(AvaloniaObject obj) | ||
{ | ||
return (Style)obj.GetValue(WindowStyleProperty); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the <see cref="WindowStyleProperty"/> attached property. | ||
/// </summary> | ||
/// <param name="obj">The target element.</param> | ||
/// <param name="value">The Style to attach.</param> | ||
public static void SetWindowStyle(AvaloniaObject obj, Style value) | ||
{ | ||
obj.SetValue(WindowStyleProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the value for the <see cref="WindowStartupLocationProperty"/> attached property. | ||
/// </summary> | ||
/// <param name="obj">The target element.</param> | ||
/// <returns>The <see cref="WindowStartupLocationProperty"/> attached to the <paramref name="obj"/> element.</returns> | ||
public static WindowStartupLocation GetWindowStartupLocation(AvaloniaObject obj) | ||
{ | ||
return (WindowStartupLocation)obj.GetValue(WindowStartupLocationProperty); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the <see cref="WindowStartupLocationProperty"/> attached property. | ||
/// </summary> | ||
/// <param name="obj">The target element.</param> | ||
/// <param name="value">The WindowStartupLocation to attach.</param> | ||
public static void SetWindowStartupLocation(AvaloniaObject obj, WindowStartupLocation value) | ||
{ | ||
obj.SetValue(WindowStartupLocationProperty, value); | ||
} | ||
|
||
private static void OnWindowStartupLocationChanged(AvaloniaObject sender, AvaloniaPropertyChangedEventArgs e) | ||
{ | ||
if (sender is Window window) | ||
window.WindowStartupLocation = (WindowStartupLocation)e.NewValue; | ||
} | ||
} | ||
} |
Oops, something went wrong.