0
我目前無法在我的UWP佈局中提出子視圖,但它適用於Android。 (相同的代碼只是改變圖像源)任何一種靈魂都可以幫助我解決這個問題?無法提高對UWP Xamarin形式的意見
下面的代碼應顯示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);
}
}
}