這裏是我的問題: 我已經得到了這些類:名單
public class CsvField
{
public string Content { get; set; }
public CsvField(string content)
{
Content = content;
}
}
public class CsvLine
{
public List<CsvField> Fields = new List<CsvField>();
public int LineNumber;
}
public static class Settings
{
public static List<string> Tags = new List<string>();
public static CsvLine AllHeaders = new CsvLine();
}
我想要做的,是顯示包含Settings.AllHeaders.Fields的每一個成員,並含有組合框列表框Settings.Tags列表中的所有成員(水平放置 - 左邊是AllHeaders的成員,旁邊是組合框)。所以,如果我有4個標題,我會得到這4個標題和4個組合框的列表,每個標題旁邊有個別標題。這些組合框中的每一個都會包含一個標籤列表。
所以,我定義一個DataTemplate:
<Window x:Class="CSV_To_Tags_App.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="clr-namespace:CSV_To_Tags_App"
Title="Window2" Height="435" Width="566">
<Window.Resources>
<DataTemplate DataType="{x:Type loc:CsvField}">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="HeaderTextBlock" HorizontalAlignment="Left" TextWrapping="Wrap"
VerticalAlignment="Top" Text="{Binding Content}"
/>
<ComboBox HorizontalAlignment="Right" VerticalAlignment="Top" Width="120"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<Label Content="Available headers" HorizontalAlignment="Left"
VerticalAlignment="Top"/>
<ListBox x:Name="HeadersListtListBox" HorizontalAlignment="Left"
Height="254" Margin="36,104,0,0" VerticalAlignment="Top" Width="452"
ItemsSource="{Binding}"/>
</Grid>
</Window>
現在,XAML代碼上面是不完整的,因爲我不知道如何: 1.綁定的TextBlock到Settings.AllHeaders.Fields.Content
2.將ComboBox綁定到標籤列表
使用中繼器http://stackoverflow.com/questions/3010131/wpf-repeater-like-control-for-collection-source –
不幸的是,我不明白怎麼例子可以幫助我。 – Loreno