मैं ItemsControl
बनाने की कोशिश कर रहा हूं जो ग्रिड को ItemsPanel
के रूप में इस तरह से उपयोग करता है कि इसमें दो कॉलम हैं, जहां पहली कॉलम चौड़ाई उस कॉलम में सबसे बड़ी वस्तु की चौड़ाई है, और जैसा कि पंक्तियां हो सकती हैं प्रदर्शित सभी आइटमआइटम नियंत्रण के लिए टेम्पलेट के रूप में ग्रिड कैसे सेट करें?
असल में, मैं निम्नलिखित चाहते हैं, लेकिन किसी भी तरह तो एक ItemsControl
भीतर मैं वस्तुओं का संग्रह करने के लिए बाध्य कर सकते हैं कि:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Label Content="{Binding Items[0].Header}"/>
<TextBox Text="{Binding Items[0].Content}" Grid.Column="1"/>
<Label Content="{Binding Items[1].Header}" Grid.Row="1"/>
<TextBox Text="{Binding Items[1].Content}" Grid.Row="1" Grid.Column="1"/>
<Label Content="{Binding Items[2].Header}" Grid.Row="2"/>
<TextBox Text="{Binding Items[2].Content}" Grid.Row="2" Grid.Column="1"/>
</Grid>
संपादित करें: राहेल जवाब महान काम किया है, यहाँ एक काम उदाहरण है ।
(मैं Grid.IsSharedSizeScope = "सही" ItemsPanel में ले जाया गया, यकीन नहीं करता है, तो राहेल (जो काम नहीं किया) ItemTemplate में रख लिए होती)
namespace WpfApplication23
{
public partial class Window1 : Window
{
public List<Item> Items { get; set; }
public Window1()
{
Items = new List<Item>()
{
new Item(){ Header="Item0", Content="someVal" },
new Item(){ Header="Item1", Content="someVal" },
new Item(){ Header="Item267676", Content="someVal" },
new Item(){ Header="a", Content="someVal" },
new Item(){ Header="bbbbbbbbbbbbbbbbbbbbbbbbbb", Content="someVal" },
new Item(){ Header="ccccccc", Content="someVal" }
};
InitializeComponent();
DataContext = this;
}
}
public class Item
{
public string Header { get; set; }
public string Content { get; set; }
}
}
<Window x:Class="WpfApplication23.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Grid.IsSharedSizeScope="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="ColumnOne" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="{Binding Header}"/>
<TextBox Text="{Binding Content}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
एक आदर्श के लिए @ उपयोग के मामले रेचेल की [ग्रिड संलग्न गुण] (http: // rachel53461। wordpress.com/2011/09/17/wpf-grids-rowcolumn-count-properties/) –
मुझे यकीन नहीं है कि यह कैसे काम करेगा, क्योंकि मेरे उदाहरण में किसी आइटम में शीर्षलेख और सामग्री दोनों शामिल हैं। – pastillman
अपनी कल्पना दोस्त का उपयोग करें। अन्यथा मुझे अपना काम पूरा करने के लिए मुझे एक घंटा या तो दें और मैं आपके लिए एक उदाहरण बना सकता हूं। –