如何使用带参数的函数作为事件处理程序? [英] How to use functions with parameters as event handlers?

查看:27
本文介绍了如何使用带参数的函数作为事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Blend(而且我对它很陌生)来创建 XAML.我有一行代码调用下面的 writeC 函数:

I am using Blend (and I'm very new to it) to create XAML. I have a line of code which calls the function writeC below:

<Button x:Name="key_c" Content="c" HorizontalAlignment="Left" Height="60" 
    Margin="243,188.667,0,0" VerticalAlignment="Top" Width="60" FontWeight="Bold"
    FontFamily="Century Gothic" FontSize="21.333" Foreground="Black" 
    Click="writeC">

这很好用.但是,我想将其更改为使用参数 "a""A" 调用函数 WriteChar,以便它调用以下 C# 函数:

This works fine. However, I would like to change it to call a function WriteChar with the parameters "a" and "A", so that it calls the following C# function:

private void writeChar(string myCharCaps, string myCharLower)

我将如何在 XAML 中编写它?

How would I write this in XAML?

推荐答案

您的点击处理程序需要遵守事件处理程序签名.如果您想让该处理程序成为您的 WriteChar 的简单包装器,那很好.更多信息请访问:http://msdn.microsoft.com/en-us/library/bb531289(v=vs.90).aspx

Your click handler needs to abide by the event handler signature. If you want to make that handler a simple wrapper around your WriteChar, that's fine. More info here: http://msdn.microsoft.com/en-us/library/bb531289(v=vs.90).aspx

这篇关于如何使用带参数的函数作为事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆