0
我想ListView與包含一些信息的擴展器。所以,我做了這個代碼。我不確定這樣的綁定擴展器是否正確。我只是嘗試綁定像ListViewItem,但是當我嘗試擴展器根本不工作。這是我的代碼。WPF:在列表視圖中的擴展器綁定
XAML:
<Grid Grid.Row="2">
<ListView x:Name="lv">
<ListView.Template>
<ControlTemplate>
<HeaderedItemsControl>
<ItemsPresenter/>
</HeaderedItemsControl>
</ControlTemplate>
</ListView.Template>
<ListView.ItemTemplate>
<DataTemplate DataType="{x:Type local:LogBase}">
<Expander Grid.Column="0" HorizontalAlignment="Center">
<Expander.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"> <!-- why this code is not wokring...? -->
<TextBlock Text="{Binding No}"/>
<TextBlock Text="{Binding Timestamp}"/>
<TextBlock Text="{Binding Type}"/>
</StackPanel>
</DataTemplate>
</Expander.HeaderTemplate>
</Expander>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
後面的代碼:
public partial class MainWindow : Window
{
public List<LogBase> logs { get; set; }
public MainWindow()
{
InitializeComponent();
logs = new List<LogBase>();
logs.Add(new LogBase()
{
No = "1",
Timestamp = "123456789",
Type = "Tcp"
});
logs.Add(new LogBase()
{
No = "2",
Timestamp = "123456789",
Type = "Tcp"
});
logs.Add(new LogBase()
{
No = "3",
Timestamp = "123456789",
Type = "Tcp"
});
lv.ItemsSource = logs;
DataContext = this;
}
}
public class LogBase
{
public string No { get; set; }
public string Timestamp { get; set; }
public string Type { get; set; }
}
更好地瞭解我拍攝我想要
如果您有任何意見,請評論爲了我!
非常感謝你......我感覺就像在雲下一樣。我錯過了什麼......但是..只是答案是Header =「{Bining}」.. –
你能回答爲什麼標題沒有綁定Listview.ItemTemplate作爲默認?我無法找到在擴展器中的MSDN –
看看https://stackoverflow.com/questions/26242734/what-does-exactly-expander-header-binding-do – Fruchtzwerg