私は、ランタイム中に動的に追加されたボタンの位置を取得する問題に直面しています。以下のコードを見つけてください。WPFで動的に追加されたコントロールの位置を取得するには?
foreach (string subfolder in Directory.GetDirectories(path))
{
Button btnSubfolder = new Button();
btnSubfolder.Name = "btnsubfolder" + column.ToString();
btnSubfolder.Content = subfolder.Substring(subfolder.LastIndexOf("\\") + 1);
btnSubfolder.Margin = new Thickness(15, 15, 10, 0);
btnSubfolder.Width = 200;
btnSubfolder.Height = 50;
btnSubfolder.HorizontalAlignment = HorizontalAlignment.Left;
btnSubfolder.SetValue(Grid.ColumnProperty, column);
grdsbFolders.Children.Add(btnSubfolder);
var location = btnSubFolder.PointToScreen(new Point(0, 0)); //here i am getting the same position for all the added controls;
}
ありがとうございます。
を同じグリッドにすべてのボタンを追加します実際には同じ場所に配置されます。 – Chrille
@chrille、問題解決の手助けはできますか? – Anjali
私の答えを参照してください。 – Chrille