0
KEY VALUE 종류를 표시하려면 테이블을 만들어야합니다.WPF : Grid의 동적 레이블 추가
아래 코드를 시도했지만 출력이 중복되어으로 엉망이되었습니다. 나는 그리드 RowDefinitions와 ColumnDefinitions를 만들 필요가 있지만 달성 할 수는 없다고 생각한다. 도와주세요.
XAML : 뒤에
<Window x:Class="GrideLabel.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Name="LabelGrid"></Grid>
</Window>
코드 :
당신은 행과 열 정의를 정의하고 자식 컨트롤에 행과 열을 할당해야public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
AddLabelDynamically();
}
private void AddLabelDynamically()
{
for (int i = 0; i < 3; i++)
{
Label nameLabel = new Label(); nameLabel.Content = "KEY :"+i.ToString();
Label dataLabel = new Label(); dataLabel.Content = "VALUE :"+i.ToString();
//I want to creatre the Seperate coloum and row to display KEY
// VALUE Pair distinctly
this.LabelGrid.Children.Add(nameLabel);
this.LabelGrid.Children.Add(dataLabel);
}
}
}