אתה רוצה DataGrid בגלל שהצורה הויזואלית נראת כטבלה, אבל בWPF הפקדים מייצגים רעיון לוגי ולא צורה ויזואלית - כי אפשר להציג הכל בכל צורה.
הויזואל שאתה רוצה הוא רשת, כלומר Grid פשוט. למעשה אני לא חושב שאתה צריך גריד, אתה צריך נטו רשימת מילים אופקית ובכל רשימה אפשרויות חילופיות ברשימה אנכית. אני הכנתי לך קוד לדוגמה, זה המחלקות:
class Word
{
public string OriginalWord { get; set; }
public List<AlternativeWord> AlternativeWords { get; private set; } = new List<AlternativeWord>();
}
class AlternativeWord
{
public string Word { get; set; }
public bool Include { get; set; }
}
זה הXAML להציג את המבנה:
<ItemsControl x:Name="wordsAltPanel" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Margin="4">
<TextBlock Text="{Binding OriginalWord}" FontWeight="Bold" />
<ItemsControl ItemsSource="{Binding AlternativeWords}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Word}" IsChecked="{Binding Include}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
זה קוד לדוגמה:
var textBox1 = new TextBox() { Text = "איסתרא בלגינא אכל נונא" };
var input = textBox1.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
var words = new List<Word>();
var rnd = new Random();
foreach (var word in input)
{
var wordItem = new Word { OriginalWord = word };
for (var i = rnd.Next(0, 4); i > 0; i--)
wordItem.AlternativeWords.Add(new AlternativeWord { Word = word + "-" + i });
words.Add(wordItem);
}
wordsAltPanel.ItemsSource = words;
תוצאה:
8c089831-2a74-4fa4-9962-6f37c3d1aed0-image.png