无法访问动态控件

时间:2013-07-22 23:13:12

标签: c# windows-8 microsoft-metro

当我尝试在StackPanel中单击动态控件时,我遇到了一些麻烦。 我正在以这种方式向Grid添加控件......

void Opt()
    {
        TextBlock Title_1 = new TextBlock();
        TextBlock Title_2 = new TextBlock();
        CheckBox Kwota_exists = new CheckBox();
        TextBox Title = new TextBox();
        StackPanel Frame = new StackPanel();
        Button OK = new Button();

        Title_1.Text = "Dodaj kategorię";
        Title_2.Text = "Aktywne kategorię";
        Kwota_exists.Content = "Stała kwota?";
        Title.Text = "Nazwa kategorii";
        OK.Content = "Dodaj";
        OK.IsEnabled = true;
        OK.IsHitTestVisible = true;
        OK.IsTabStop = true;
        OK.ClickMode = ClickMode.Release;
        Frame.IsHitTestVisible = true;

        Kwota_exists.Checked +=Kwota_exists_Checked;

        Title_1.FontSize = 50;
        Title_2.FontSize = 50;
        Title.FontSize = 20;
        Frame.Height = 100;
        Frame.Width = 400;

        Title_1.Margin = new Thickness(0, 0, 0, 0);
        Title_2.Margin = new Thickness(0, 220, 0, 0);
        Frame.Margin = new Thickness(0, 70, 0, 0);

        Frame.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
        Frame.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
        Frame.Orientation = Orientation.Horizontal;

        Frame.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(145, 56, 234, 21));

        Frame.Children.Add(Kwota_exists);
        Frame.Children.Add(Title);
        Frame.Children.Add(OK);


        GrdContent.Children.Add(Frame);
        GrdContent.Children.Add(Title_1);
        GrdContent.Children.Add(Title_2);

    }

但是当我试图点击按钮或检查复选框控件似乎没有响应(无法点击)。 看起来我无法访问它们或者我做错了什么。如果有人向我解释我在哪里犯错误,我会有成绩。

0 个答案:

没有答案