gpt4 book ai didi

wpf - 如何在 WPF 中动态添加详细信息行?

转载 作者:行者123 更新时间:2023-12-04 19:46:49 25 4
gpt4 key购买 nike

我能想到的唯一示例是在 html 中 - 如果您在其中动态添加一个带有 colspan + div 的 TR,例如在单击前一个 TR 时包含详细信息(可编辑)

我正在尝试理解 XAML,并想看看是否有人可以通过这个古怪的请求为我指明正确的方向。

最佳答案

这里有一些东西,不知道是不是你要找的:

XAML:

<Grid Name="_mainGrid">
<Grid.ColumnDefinitions>
<!-- Contains the button -->
<ColumnDefinition Width="Auto"/>
<!-- Contains the edit control -->
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<!-- So that we have the 'empty' space at the end -->
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
</Grid>

代码:

    public Window1()
{
InitializeComponent();
CreateRow(); // Bootstrap
}

private void CreateRow()
{
RowDefinition newRow = new RowDefinition();
newRow.Height = new GridLength(0, GridUnitType.Auto);
_mainGrid.RowDefinitions.Insert(_mainGrid.RowDefinitions.Count - 1, newRow);

int rowIndex = _mainGrid.RowDefinitions.Count - 2;

UIElement editControl = CreateEditControl();
Grid.SetRow(editControl, rowIndex);
Grid.SetColumn(editControl, 1);
Grid.SetRowSpan(editControl, 1);
Grid.SetColumnSpan(editControl, 1); // Change this if you want.
_mainGrid.Children.Add(editControl);

Button addButton = new Button();
addButton.Content = "Add";
addButton.Click += new RoutedEventHandler(b_Click);
Grid.SetRow(addButton, rowIndex);
Grid.SetColumn(addButton, 0);
_mainGrid.Children.Add(addButton);
addButton.Tag = editControl;

}

void b_Click(object sender, RoutedEventArgs e)
{
CreateRow();
Control button = (Control)sender;
UIElement editControl = (UIElement)button.Tag;
_mainGrid.Children.Remove(button);
Grid.SetColumn(editControl, 0);
Grid.SetColumnSpan(editControl, 2);
}

private UIElement CreateEditControl()
{
return new TextBox();
}

关于wpf - 如何在 WPF 中动态添加详细信息行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/555025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com