Xamarin实验室复选框ios不工作

时间:2016-08-29 05:50:55

标签: xamarin xamarin.ios xamarin.forms

我在Xamarin论坛上提出了同样的问题,但没有人回答我的问题。

我正在使用X实验室和我的代码,如下所示。

我的便携式项目的ContentPage;

public class CheckBoxPage : ContentPage
{
    public CheckBoxPage()
    {
        CheckBox check = new CheckBox
        {
            TextColor = Color.Red,
            BackgroundColor = Color.Black,
            HorizontalOptions = LayoutOptions.FillAndExpand
        };
        CheckBox unCheck = new CheckBox
        {
            TextColor = Color.Yellow,
            BackgroundColor = Color.Black,
            HorizontalOptions = LayoutOptions.FillAndExpand
        };
        Content = new StackLayout
        {
            Children = {
                check, unCheck
            }
        };
    }
}

我的Android和iOS外观不同。 iOS外观不像一个复选框。但Android运行良好。为什么呢?

Android Appearence is

iOs appearence is

3 个答案:

答案 0 :(得分:1)

非常感谢

关于设计不可编辑。所以我有一个代码示例;

class CheckBox : Image
{
    public CheckBox(bool isChecked)
    {
        Resources = new ResourceDictionary();

        if(isChecked) 
            Resources.Add("ImageName", "checked.png");
        else
            Resources.Add("ImageName", "unchecked.png");

        var resourceName = Resources["ImageName"];
        Source = ImageSource.FromFile(resourceName.ToString());

        TapGestureRecognizer t = new TapGestureRecognizer();
        t.Tapped += OnScreenTapped;
        this.GestureRecognizers.Add(t);
    }

    public void OnScreenTapped(object sender, EventArgs args)
    {
        var resourceName = Resources["ImageName"];
        if (resourceName.ToString() == "unchecked.png")
        {
            Resources["ImageName"] = "checked.png";
            Source = ImageSource.FromFile("checked.png");
        }
        else
        {
            Resources["ImageName"] = "unchecked.png";
            Source = ImageSource.FromFile("unchecked.png");
        }
    }

    public bool isChecked()
    {
        var resourceName = Resources["ImageName"];
        if (resourceName.ToString() == "unchecked.png")
            return false;
        else
            return true;
    }
}

使用此customCheckBox

CheckBox mychceck = new CheckBox(true);

这对于自定义设计更有用。

答案 1 :(得分:0)

我尝试将相同的示例与您的代码一起运行。

原来我在iOS中也得到了类似的输出。

这似乎是XLabs的问题,经过检查后我发现them存在多个问题。

更恰当的是:

可能最好加入同一个帖子。

,您可以尝试一下:

希望它有所帮助!

答案 2 :(得分:0)

Xamarin IOS和Android中的自定义复选框

设计方:

<div class="panel panel-primary">
    <div class="panel-heading clearfix">
        <div class="panel-heading">
            Manage Person
        </div>
    </div>
</div>
<div class="btn-group pull-right">
    <a asp-action="Create" asp-controller="Persons" class="btn btn-primary btn-group-sm">
        Add Person
    </a>
</div>

<div class="panel-body">
    <div class="row">
        <div class="col-md-12">
            <table class="table table-bordered table-striped table-hover">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Age</th>
                        <th>Gender</th>
                        <th>Height</th>                    
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Rachel</td>
                        <td>25</td>
                        <td>Female</td>
                        <td>175cm</td>
                    </tr>
                    <tr>
                        <td>Thomas</td>
                        <td>15</td>
                        <td>Male</td>
                        <td>165cm</td>
                    </tr>
                    <tr>
                        <td>Jared</td>
                        <td>40</td>
                        <td>Male</td>
                        <td>195cm</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

编码方:

private void TapGestureRecognizerForCheckStaff(object sender,EventArgs e)         {

<Image Source="unchecked_checkbox" >
     <Image.GestureRecognizers >
         <TapGestureRecognizer Tapped="TapGestureRecognizerForCheckStaff" />
       </Image.GestureRecognizers>
</Image>