gpt4 book ai didi

c# - 如何以编程方式推送 ToggleButton?

转载 作者:行者123 更新时间:2023-12-05 00:50:44 28 4
gpt4 key购买 nike

我有这段代码可以以编程方式按下按钮,但我想要一个适用于 ToggleButton 的版本。

public static void PushButton(Button b)
{
ButtonAutomationPeer peer = new ButtonAutomationPeer(b);
System.Windows.Automation.Provider.IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider;
invokeProv.Invoke();
}

所以我尝试了 ToggleButtonAutomationPeer...

public static void PushButton(ToggleButton b)
{
ToggleButtonAutomationPeer peer = new ToggleButtonAutomationPeer(b);
System.Windows.Automation.Provider.IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as System.Windows.Automation.Provider.IInvokeProvider;

//But invokeProv is null. Peer is ok.
}

最佳答案

您可以使用 Toggle Button Automation Peer

public static void PushToggleButton(ToggleButton b)
{
ToggleButtonAutomationPeer peer = new ToggleButtonAutomationPeer(b);
System.Windows.Automation.Provider.IToggleProvider toggleProvider = peer.GetPattern(PatternInterface.Toggle) as System.Windows.Automation.Provider.IToggleProvider;
toggleProvider.Toggle();
}

关于c# - 如何以编程方式推送 ToggleButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10148264/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com