зеркало из https://github.com/DeGsoft/maui-linux.git
[WPF] Frame: Add shadow and padding (#7964)
* Add frame border sample * Add padding and shadow to frame * Change name of issue repro to correct issue id * Correct issue title and platform target * Improve shadow handling; ensure correct background * Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7963.cs Co-Authored-By: Gerald Versluis <github@geraldversluis.nl> * Update Xamarin.Forms.Platform.WPF/Renderers/FrameRenderer.cs Co-Authored-By: Gerald Versluis <github@geraldversluis.nl> * Update Xamarin.Forms.Platform.WPF/Renderers/FrameRenderer.cs Co-Authored-By: Gerald Versluis <github@geraldversluis.nl> * Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7963.cs Co-Authored-By: Gerald Versluis <github@geraldversluis.nl> * Update Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7963.cs Co-Authored-By: Gerald Versluis <github@geraldversluis.nl> * Add back the precious issue pages * Correct merge errors * Remove background workaround
This commit is contained in:
Родитель
ab9fabf04b
Коммит
8f4c0e4805
|
@ -0,0 +1,54 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 7963, "WPF frame padding, shadow missing?", PlatformAffected.WPF)]
|
||||
public class Issue7963 : TestContentPage
|
||||
{
|
||||
protected override void Init()
|
||||
{
|
||||
Content = new StackLayout
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new Frame()
|
||||
{
|
||||
HasShadow = false,
|
||||
Margin = 10,
|
||||
HeightRequest = 100,
|
||||
Content = new Label { Text = "Frame without shadow" }
|
||||
},
|
||||
new Frame()
|
||||
{
|
||||
HasShadow = true,
|
||||
Margin = 10,
|
||||
HeightRequest = 100,
|
||||
Content = new Label { Text = "Frame with shadow" }
|
||||
},
|
||||
new ContentView
|
||||
{
|
||||
Content =new Frame()
|
||||
{
|
||||
HasShadow = true,
|
||||
Margin = 10,
|
||||
HeightRequest = 100,
|
||||
Content = new Label { Text = "Frame with shadow above green background" }
|
||||
},
|
||||
BackgroundColor = Color.Green
|
||||
},
|
||||
new Frame()
|
||||
{
|
||||
HasShadow = true,
|
||||
Margin = 10,
|
||||
BackgroundColor = Color.Blue,
|
||||
HeightRequest = 100,
|
||||
Content = new Label { Text = "Frame with shadow and background color" }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -142,6 +142,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue8508.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue7963.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)RefreshViewTests.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue7338.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ScrollToGroup.cs" />
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Effects;
|
||||
using WThickness = System.Windows.Thickness;
|
||||
|
||||
namespace Xamarin.Forms.Platform.WPF
|
||||
{
|
||||
|
@ -50,6 +46,8 @@ namespace Xamarin.Forms.Platform.WPF
|
|||
UpdateContent();
|
||||
UpdateBorder();
|
||||
UpdateCornerRadius();
|
||||
UpdatePadding();
|
||||
UpdateShadow();
|
||||
}
|
||||
|
||||
base.OnElementChanged(e);
|
||||
|
@ -59,19 +57,18 @@ namespace Xamarin.Forms.Platform.WPF
|
|||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if (e.PropertyName == Frame.ContentProperty.PropertyName)
|
||||
if (e.PropertyName == ContentView.ContentProperty.PropertyName)
|
||||
UpdateContent();
|
||||
else if (e.PropertyName == Frame.BorderColorProperty.PropertyName || e.PropertyName == Frame.HasShadowProperty.PropertyName)
|
||||
else if (e.PropertyName == Frame.BorderColorProperty.PropertyName)
|
||||
UpdateBorder();
|
||||
else if (e.PropertyName == Frame.HasShadowProperty.PropertyName)
|
||||
UpdateShadow();
|
||||
else if (e.PropertyName == Frame.CornerRadiusProperty.PropertyName)
|
||||
UpdateCornerRadius();
|
||||
else if (e.PropertyName == Button.PaddingProperty.PropertyName)
|
||||
UpdatePadding();
|
||||
}
|
||||
|
||||
protected override void UpdateBackground()
|
||||
{
|
||||
Control.UpdateDependencyColor(Border.BackgroundProperty, Element.BackgroundColor);
|
||||
}
|
||||
|
||||
|
||||
void UpdateContent()
|
||||
{
|
||||
if (_currentView != null)
|
||||
|
@ -93,16 +90,48 @@ namespace Xamarin.Forms.Platform.WPF
|
|||
}
|
||||
else
|
||||
{
|
||||
Control.UpdateDependencyColor(Border.BorderBrushProperty, new Color(0, 0, 0, 0));
|
||||
Control.UpdateDependencyColor(Border.BorderBrushProperty, Color.Transparent);
|
||||
Control.BorderThickness = new System.Windows.Thickness(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void UpdateShadow()
|
||||
{
|
||||
if (Element.HasShadow)
|
||||
{
|
||||
Control.Effect = new DropShadowEffect()
|
||||
{
|
||||
Color = Colors.Gray,
|
||||
Direction = 320,
|
||||
Opacity = 0.5,
|
||||
BlurRadius = 6,
|
||||
ShadowDepth = 2
|
||||
};
|
||||
}
|
||||
else if(Control.Effect is DropShadowEffect)
|
||||
{
|
||||
Control.Effect = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateBackground()
|
||||
{
|
||||
Control.UpdateDependencyColor(Border.BackgroundProperty, Element.BackgroundColor);
|
||||
}
|
||||
|
||||
void UpdateCornerRadius()
|
||||
{
|
||||
Control.CornerRadius = new System.Windows.CornerRadius(Element.CornerRadius >= 0 ? Element.CornerRadius : 0);
|
||||
_rounding.CornerRadius = Control.CornerRadius;
|
||||
}
|
||||
|
||||
void UpdatePadding()
|
||||
{
|
||||
Control.Padding = new WThickness(
|
||||
Element.Padding.Left,
|
||||
Element.Padding.Top,
|
||||
Element.Padding.Right,
|
||||
Element.Padding.Bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
@ -136,9 +135,9 @@ namespace Xamarin.Forms.Platform.WPF
|
|||
{
|
||||
if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
|
||||
UpdateEnabled();
|
||||
else if (e.PropertyName == Frame.HeightProperty.PropertyName)
|
||||
else if (e.PropertyName == VisualElement.HeightProperty.PropertyName)
|
||||
UpdateHeight();
|
||||
else if (e.PropertyName == Frame.WidthProperty.PropertyName)
|
||||
else if (e.PropertyName == VisualElement.WidthProperty.PropertyName)
|
||||
UpdateWidth();
|
||||
else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
|
||||
UpdateBackground();
|
||||
|
|
Загрузка…
Ссылка в новой задаче