【发布时间】:2017-09-26 11:14:38
【问题描述】:
我目前无法在我的 UWP 布局中提升子视图,但它适用于 android。 (相同的代码只是更改图像源)任何善良的灵魂可以帮助我解决这个问题?
下面的代码应该显示 2 个图像和 2 个按钮。当我测试图像是否会成功提升时,图像会相互重叠。在 android 上,它工作得很好,但在 UWP 上却不行,我不确定我可能错过了什么,因为 PCL 应该是常见的,所以代码应该在两个平台上都可以正常工作。
下面是我的代码:
MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:UWPRaiseTest"
x:Class="UWPRaiseTest.MainPage">
<ContentView>
<StackLayout Orientation="Vertical" BackgroundColor="Violet" x:Name="EntireLayout" IsEnabled="True">
<RelativeLayout x:Name="ImageHolder" IsEnabled="True">
<Image x:Name="Img1" Source="Assets/StoreLogo.png" BackgroundColor="AliceBlue" IsEnabled="True"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0,Constant=100}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0, Constant=0}" />
<Image x:Name="Img2" Source="Assets/StoreLogo.png" BackgroundColor="Red" IsEnabled="True"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0,Constant=120}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0, Constant=0}" />
</RelativeLayout>
<Button x:Name="RaiseObj1" BackgroundColor="Aquamarine" Text="Raise image 1 " Clicked="RaiseObj1_OnClicked" />
<Button x:Name="RaiseObj2" BackgroundColor="Aquamarine" Text="Raise image 2" Clicked="RaiseObj2_OnClicked"/>
</StackLayout>
</ContentView>
</ContentPage>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace UWPRaiseTest
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void RaiseObj1_OnClicked(object sender, EventArgs e)
{
ImageHolder.RaiseChild(Img1);
ImageHolder.LowerChild(Img2);
EntireLayout.RaiseChild(Img1);
}
private void RaiseObj2_OnClicked(object sender, EventArgs e)
{
ImageHolder.RaiseChild(Img2);
EntireLayout.RaiseChild(Img2);
ImageHolder.LowerChild(Img1);
}
}
}
【问题讨论】:
标签: c# xamarin.forms uwp