【发布时间】:2018-06-28 08:47:01
【问题描述】:
我想在 Xamarin.Forms 项目上更改 UWP 切换开关的颜色。我认为有两种方法可以解决它,即自定义渲染器或效果。所以我尝试制作效果,但似乎我仍然无法更改切换开关的边框。有好心人帮帮我吗?
以下是我的代码: 在 UWP 中,FocusEffect.cs 文件,
namespace EffectsDemo.UWP
{
public class FocusEffect : PlatformEffect
{
protected override void OnAttached()
{
try
{
(Control as Windows.UI.Xaml.Controls.Control).Background = new SolidColorBrush(Colors.Black);
(Control as Windows.UI.Xaml.Controls.Control).BorderBrush = new SolidColorBrush(Colors.Yellow);
(Control as Windows.UI.Xaml.Controls.Control).Foreground = new SolidColorBrush(Colors.Green);
(Element as Switch).IsInNativeLayout = false;
(Control as ToggleSwitch).BorderBrush = new SolidColorBrush(Colors.WhiteSmoke);
(Control as ToggleSwitch).BorderThickness = new Windows.UI.Xaml.Thickness(500);
}
catch (Exception ex)
{
Debug.WriteLine("Cannot set property on attached control. Error: ", ex.Message);
}
}
protected override void OnDetached()
{
}
}
【问题讨论】:
标签: c# xamarin.forms uwp xamarin.uwp