【问题标题】:Handlers of elements of WrapPanelWrapPanel 元素的处理程序
【发布时间】:2012-04-05 22:39:33
【问题描述】:

我已经动态创建了带有多个边框的 WrapPanel (_wp)。我需要为每个边框创建处理程序。我怎样才能通过 C# 做到这一点?

        for (int k = 1; k < i+1; k++)
        {
            _b = new Border()
            {
                Margin = new Thickness(0, 5, 5, 0),
                BorderBrush = new SolidColorBrush(Colors.Blue),
                BorderThickness = new Thickness(3, 3, 3, 3),
                Background = new SolidColorBrush(Colors.Transparent),
                Child = new TextBlock()
                {
                    Text = k.ToString(),
                    HorizontalAlignment = System.Windows.HorizontalAlignment.Center,
                    VerticalAlignment = System.Windows.VerticalAlignment.Center,
                    FontSize = 28,
                }
            };
            _wp.Children.Add(_b); 
        }

我需要 Tap 处理程序。

【问题讨论】:

    标签: c# windows-phone-7


    【解决方案1】:

    随便用

     _b.Tap += yourHandler;
    

    【讨论】:

    • 是的,我认为我需要在创建每个边框的过程中这样做。所以,这是一个非常愚蠢的问题 :) 谢谢!
    • @Max:不客气!事实上,像 XAML 中的 Tap="handler" 这样的代码会使用 += 转换成完全相同的代码(您可以在 obj\...\formName.g.cs 中查看)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多