WPFToolkit AccordionItem内容在点击时不会扩展

时间:2017-03-06 06:02:26

标签: c# wpf

我正在使用WPFToolkit Accordion控件,我有以下代码可以在单击一个Accordion Item时添加内容:

Grid grd = new Grid();
grd.Background = Brushes.Black;

ColumnDefinition colDef = new ColumnDefinition();
colDef.Width = new GridLength(4, GridUnitType.Star);
grd.ColumnDefinitions.Add(colDef);

ColumnDefinition colDef2 = new ColumnDefinition();
colDef2.Width = new GridLength(1, GridUnitType.Star);
grd.ColumnDefinitions.Add(colDef2);

Style stlName = this.FindResource("lblChamp") as Style;
Style stlFav = this.FindResource("imgChamp") as Style;

foreach (ChampsBySport champ in champs)
{
    RowDefinition rDef = new RowDefinition();
    grd.RowDefinitions.Add(rDef);

    Label lbl = new Label();
    lbl.Content = champ.title;
    lbl.ToolTip = champ.title;
    lbl.Style = stlName;
    lbl.Name = "lblChamp" + champ.champ_id;
    lbl.MouseEnter += new MouseEventHandler(lblChamp_MouseEnter);
    grd.Children.Add(lbl);

    Grid.SetRow(lbl, grd.RowDefinitions.Count - 1);

    Image img = new Image();
    img.Style = stlFav;
    img.Source = new BitmapImage(new Uri("../img/menu/fav.png", UriKind.Relative));
    img.Name = "imgChamp" + champ.champ_id;
    grd.Children.Add(img);

    Grid.SetRow(img, grd.RowDefinitions.Count - 1);
}

accItem.Content = grd;

accMain.Height += grd.ActualHeight;

此代码不稳定。它不会一直有效。我的意思是有时候我会点击A​​ccordion Item并且它会完美展开,但有些时候有很多内容时它在点击时都没有显示任何内容。没有异常抛出。这段代码有什么问题?我错过了什么吗?

0 个答案:

没有答案