微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Xamarin.iOS 中创建自定义渲染器时,如何将默认渲染器添加到视图?

如何解决在 Xamarin.iOS 中创建自定义渲染器时,如何将默认渲染器添加到视图?

我为 Xamarin 应用程序中的按钮创建了一个自定义渲染器。 iOS 中的所有按钮都使用此渲染器。我想要一个特定的按钮不使用自定义渲染器,而是使用认渲染器。如何将认渲染器分配给一个按钮?

这是我的 Customrenderer 的外观:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select

browser = webdriver.Chrome()

url = <url>
browser.get(url)

export1 = browser.find_element_by_xpath("//*[@id=\"react-main-content\"]/div[1]/section/div[1]/div[3]/div[2]/div/button")
time.sleep(1)
export1.click()

# This is the element it's unable to locate
webdriverwait(browser,10).until(EC.element_to_be_clickable((By.XPATH,"/html/body/div[4]/div/div/ul/li[3]/li/button")))

# Execution never reaches this point
export2 = browser.find_element_by_xpath("/html/body/div[4]/div/div/ul/li[3]/li/button")
export2.click()

解决方法

在您的共享项目中创建自定义 Button

public class CustomButton : Button
{

}

将自定义渲染器分配给 CustomButton 类型:

[assembly: ExportRenderer(typeof(CustomButton),typeof(CustomRenderer))]
namespace Test.iOS
{
    public class CustomRenderer : ButtonRenderer
{...}}

每当您希望按钮使用默认渲染器时,请使用 <Button ,并且每当您希望它使用自定义渲染器时,请使用 <CustomButton

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。