单击

时间:2017-01-12 12:03:28

标签: wpf wpf-controls stackpanel

  • 我在WPF应用程序中使用高度= 200,宽度= 200的堆栈面板。
  • 默认情况下不可见。
  • 我想在左键单击时显示堆栈面板并想要设置它 位置与鼠标指针相同。

任何人都可以告诉我该怎么做。谢谢:)

1 个答案:

答案 0 :(得分:1)

您可以通过处理MouseLeftButtonDown事件并将StackPanel的Visibility设置为Visible来使其可见。为了能够使用坐标显式定位它,您可以将它放在Canvas中并处理Canvas的MouseLeftButtonDown事件。请参阅以下示例代码。

   from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTShadowClient
   import logging
   import json 


def get(payload, responseStatus, token):
    dict = json.loads(payload)
    print(str(dict["state"]["desired"]["State"])) #make sure this matches your shadow names



# Read in command-line parameters
useWebsocket = False
host = "XXXXXYourINFO HEREXXXXXX.iot.us-east-1.amazonaws.com"
rootCAPath = "XXXXXYourINFO HEREXXXXXX"
certificatePath = "XXXXXYourINFO HEREXXXXXX"
privateKeyPath = "XXXXXYourINFO HEREXXXXXX"


# Configure logging
logger = logging.getLogger("AWSIoTPythonSDK.core")
logger.setLevel(logging.DEBUG)
streamHandler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
streamHandler.setFormatter(formatter)
logger.addHandler(streamHandler)

# Init AWSIoTMQTTShadowClient

myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("basicShadowUpdater")
myAWSIoTMQTTShadowClient.configureEndpoint(host, 8883)
myAWSIoTMQTTShadowClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)

# AWSIoTMQTTShadowClient configuration
myAWSIoTMQTTShadowClient.configureAutoReconnectBackoffTime(1, 32, 20)
myAWSIoTMQTTShadowClient.configureConnectDisconnectTimeout(10)  # 10 sec
myAWSIoTMQTTShadowClient.configureMQTTOperationTimeout(5)  # 5 sec

# Connect to AWS IoT
myAWSIoTMQTTShadowClient.connect()

# Create a deviceShadow with persistent subscription
Bot = myAWSIoTMQTTShadowClient.createShadowHandlerWithName("GarageRBP", True)

#get the shadow here and the state is included in the custom callback
Bot.shadowGet(get, 5)