나는 초보자이며 ListBox.GroupStyle의 일부 구문을 혼동합니다. 코드 :WPF에서 바인딩 경로 = 이름 의미는 무엇입니까?
<Window x:Class="testCollectionViewSource.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">
<Window.Resources>
<CollectionViewSource x:Key="CVS" Source="{Binding Path=Cs}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="B" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Window.Resources>
<Grid>
<ListBox ItemsSource="{Binding Source={StaticResource CVS}}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding S}"/>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"/>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Cs = new ObservableCollection<C>();
Cs.Add(new C(true, "1"));
Cs.Add(new C(false, "2"));
Cs.Add(new C(true, "3"));
Cs.Add(new C(false, "4"));
DataContext = this;
}
public ObservableCollection<C> Cs { get; set; }
}
public class C
{
public C(bool b, string s)
{
B = b;
S = s;
}
public bool B { get; set; }
public string S { get; set; }
}
그래서 제 질문은 {이름 바인딩} 왜 아니라 헤더에 "true"또는 "false"왜 작동하지 {B 바인딩}합니까? 클래스 C에는 해당 속성이 없으므로 "이름"은 무엇을 의미합니까?
+1 좋은 답변입니다. 나는 '스눕 (Snoop)'에 대해 몰랐다. – gleng