committed by
GitHub
33 changed files with 681 additions and 195 deletions
@ -1,64 +0,0 @@ |
|||
function Get-NewDirectoryName { |
|||
param ([System.IO.DirectoryInfo]$item) |
|||
|
|||
$name = $item.Name.Replace("perspex", "avalonia") |
|||
$name = $name.Replace("Perspex", "Avalonia") |
|||
Join-Path $item.Parent.FullName $name |
|||
} |
|||
|
|||
function Get-NewFileName { |
|||
param ([System.IO.FileInfo]$item) |
|||
|
|||
$name = $item.Name.Replace("perspex", "avalonia") |
|||
$name = $name.Replace("Perspex", "Avalonia") |
|||
Join-Path $item.DirectoryName $name |
|||
} |
|||
|
|||
function Rename-Contents { |
|||
param ([System.IO.FileInfo] $file) |
|||
|
|||
$extensions = @(".cs",".xaml",".csproj",".sln",".md",".json",".yml",".partial",".ps1",".nuspec",".htm",".html",".gitmodules".".xml",".plist",".targets",".projitems",".shproj",".xib") |
|||
|
|||
if ($extensions.Contains($file.Extension)) { |
|||
$text = [IO.File]::ReadAllText($file.FullName) |
|||
$text = $text.Replace("github.com/perspex", "github.com/avaloniaui") |
|||
$text = $text.Replace("github.com/Perspex", "github.com/AvaloniaUI") |
|||
$text = $text.Replace("perspex", "avalonia") |
|||
$text = $text.Replace("Perspex", "Avalonia") |
|||
$text = $text.Replace("PERSPEX", "AVALONIA") |
|||
[IO.File]::WriteAllText($file.FullName, $text) |
|||
} |
|||
} |
|||
|
|||
function Process-Files { |
|||
param ([System.IO.DirectoryInfo] $item) |
|||
|
|||
$dirs = Get-ChildItem -Path $item.FullName -Directory |
|||
$files = Get-ChildItem -Path $item.FullName -File |
|||
|
|||
foreach ($dir in $dirs) { |
|||
Process-Files $dir.FullName |
|||
} |
|||
|
|||
foreach ($file in $files) { |
|||
Rename-Contents $file |
|||
|
|||
$renamed = Get-NewFileName $file |
|||
|
|||
if ($file.FullName -ne $renamed) { |
|||
Write-Host git mv $file.FullName $renamed |
|||
& git mv $file.FullName $renamed |
|||
} |
|||
} |
|||
|
|||
$renamed = Get-NewDirectoryName $item |
|||
|
|||
if ($item.FullName -ne $renamed) { |
|||
Write-Host git mv $item.FullName $renamed |
|||
& git mv $item.FullName $renamed |
|||
} |
|||
} |
|||
|
|||
& git submodule deinit . |
|||
& git clean -xdf |
|||
Process-Files . |
|||
@ -1,29 +1,27 @@ |
|||
using Avalonia.Controls; |
|||
|
|||
namespace Avalonia.Styling |
|||
namespace Avalonia.Controls |
|||
{ |
|||
/// <summary>
|
|||
/// Defines an interface through which a <see cref="Style"/>'s parent can be set.
|
|||
/// Defines an interface through which an <see cref="IResourceNode"/>'s parent can be set.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// You should not usually need to use this interface - it is for internal use only.
|
|||
/// </remarks>
|
|||
public interface ISetStyleParent : IStyle |
|||
public interface ISetResourceParent : IResourceNode |
|||
{ |
|||
/// <summary>
|
|||
/// Sets the style parent.
|
|||
/// Sets the resource parent.
|
|||
/// </summary>
|
|||
/// <param name="parent">The parent.</param>
|
|||
void SetParent(IResourceNode parent); |
|||
|
|||
/// <summary>
|
|||
/// Notifies the style that a change has been made to resources that apply to it.
|
|||
/// Notifies the resource node that a change has been made to the resources in its parent.
|
|||
/// </summary>
|
|||
/// <param name="e">The event args.</param>
|
|||
/// <remarks>
|
|||
/// This method will be called automatically by the framework, you should not need to call
|
|||
/// this method yourself.
|
|||
/// </remarks>
|
|||
void NotifyResourcesChanged(ResourcesChangedEventArgs e); |
|||
void ParentResourcesChanged(ResourcesChangedEventArgs e); |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
namespace Avalonia.Media |
|||
{ |
|||
/// <summary>
|
|||
/// Describes the type of scaling that can be used when scaling content.
|
|||
/// </summary>
|
|||
public enum StretchDirection |
|||
{ |
|||
/// <summary>
|
|||
/// Only scales the content upwards when the content is smaller than the available space.
|
|||
/// If the content is larger, no scaling downwards is done.
|
|||
/// </summary>
|
|||
UpOnly, |
|||
|
|||
/// <summary>
|
|||
/// Only scales the content downwards when the content is larger than the available space.
|
|||
/// If the content is smaller, no scaling upwards is done.
|
|||
/// </summary>
|
|||
DownOnly, |
|||
|
|||
/// <summary>
|
|||
/// Always stretches to fit the available space according to the stretch mode.
|
|||
/// </summary>
|
|||
Both, |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
// Copyright (c) The Avalonia Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.Presenters; |
|||
using Avalonia.Controls.Templates; |
|||
using Avalonia.Media; |
|||
using Avalonia.Styling; |
|||
using Avalonia.UnitTests; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Markup.Xaml.UnitTests.Xaml |
|||
{ |
|||
public class ResourceDictionaryTests : XamlTestBase |
|||
{ |
|||
[Fact] |
|||
public void StaticResource_Works_In_ResourceDictionary() |
|||
{ |
|||
using (StyledWindow()) |
|||
{ |
|||
var xaml = @"
|
|||
<ResourceDictionary xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<Color x:Key='Red'>Red</Color> |
|||
<SolidColorBrush x:Key='RedBrush' Color='{StaticResource Red}'/> |
|||
</ResourceDictionary>";
|
|||
var loader = new AvaloniaXamlLoader(); |
|||
var resources = (ResourceDictionary)loader.Load(xaml); |
|||
var brush = (SolidColorBrush)resources["RedBrush"]; |
|||
|
|||
Assert.Equal(Colors.Red, brush.Color); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void DynamicResource_Works_In_ResourceDictionary() |
|||
{ |
|||
using (StyledWindow()) |
|||
{ |
|||
var xaml = @"
|
|||
<ResourceDictionary xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<Color x:Key='Red'>Red</Color> |
|||
<SolidColorBrush x:Key='RedBrush' Color='{DynamicResource Red}'/> |
|||
</ResourceDictionary>";
|
|||
var loader = new AvaloniaXamlLoader(); |
|||
var resources = (ResourceDictionary)loader.Load(xaml); |
|||
var brush = (SolidColorBrush)resources["RedBrush"]; |
|||
|
|||
Assert.Equal(Colors.Red, brush.Color); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void DynamicResource_Finds_Resource_In_Parent_Dictionary() |
|||
{ |
|||
var dictionaryXaml = @"
|
|||
<ResourceDictionary xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<SolidColorBrush x:Key='RedBrush' Color='{DynamicResource Red}'/> |
|||
</ResourceDictionary>";
|
|||
|
|||
using (StyledWindow(assets: ("test:dict.xaml", dictionaryXaml))) |
|||
{ |
|||
var xaml = @"
|
|||
<Window xmlns='https://github.com/avaloniaui'
|
|||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
|
|||
<Window.Resources> |
|||
<ResourceDictionary> |
|||
<ResourceDictionary.MergedDictionaries> |
|||
<ResourceInclude Source='test:dict.xaml'/> |
|||
</ResourceDictionary.MergedDictionaries> |
|||
</ResourceDictionary> |
|||
<Color x:Key='Red'>Red</Color> |
|||
</Window.Resources> |
|||
<Button Name='button' Background='{DynamicResource RedBrush}'/> |
|||
</Window>";
|
|||
|
|||
var loader = new AvaloniaXamlLoader(); |
|||
var window = (Window)loader.Load(xaml); |
|||
var button = window.FindControl<Button>("button"); |
|||
|
|||
var brush = Assert.IsType<SolidColorBrush>(button.Background); |
|||
Assert.Equal(Colors.Red, brush.Color); |
|||
|
|||
window.Resources["Red"] = Colors.Green; |
|||
|
|||
Assert.Equal(Colors.Green, brush.Color); |
|||
} |
|||
} |
|||
|
|||
private IDisposable StyledWindow(params (string, string)[] assets) |
|||
{ |
|||
var services = TestServices.StyledWindow.With( |
|||
assetLoader: new MockAssetLoader(assets), |
|||
theme: () => new Styles |
|||
{ |
|||
WindowStyle(), |
|||
}); |
|||
|
|||
return UnitTestApplication.Start(services); |
|||
} |
|||
|
|||
private Style WindowStyle() |
|||
{ |
|||
return new Style(x => x.OfType<Window>()) |
|||
{ |
|||
Setters = |
|||
{ |
|||
new Setter( |
|||
Window.TemplateProperty, |
|||
new FuncControlTemplate<Window>((x, scope) => |
|||
new ContentPresenter |
|||
{ |
|||
Name = "PART_ContentPresenter", |
|||
[!ContentPresenter.ContentProperty] = x[!Window.ContentProperty], |
|||
}.RegisterInNameScope(scope))) |
|||
} |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue