0
제목이 새겨 져 있습니다. 더 잘하면 편집하십시오. 나는이 같은 자원 WPF에서 만든 객체를 사용하는 경우메인 윈도우에있는 오브젝트를 붙이십시오.
내가 작업 코드를 가지고 :
<Grid>
<Grid.Resources>
<local:PersonView x:Key="Persons"/>
<CollectionViewSource x:Key="ViewPersons" Source="{Binding Source={StaticResource Persons}, Path=Persons}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Name"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</Grid.Resources>
<ListView ItemsSource="{Binding Source={StaticResource ViewPersons}}">
<ListView.View>
<GridView>
<GridViewColumn Width="100" Header="Name" DisplayMemberBinding="{Binding Name}"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
:
<local:PersonView x:Key="Persons"/>
하지만 MainWindow를에서 만든 객체를 사용하려면, 여기에 작업 코드
public class Person
{
public string Name { get; set; }
}
public class PersonView
{
public ObservableCollection<Person> Persons { get; set; }
public PersonView()
{
Persons = new ObservableCollection<Person>();
Persons.Add(new Person() { Name = "Luis" });
Persons.Add(new Person() { Name = "Gusth" });
}
}
이 코드가 작동,하지만 난 CollectionViewSource의 t을 바인딩 할 :
클래스는 내가 사용 MainWindow를에서 만든 오 개체 :
public partial class MainWindow : Window
{
public PersonView BindThis { get; set; }
public MainWindow()
{
InitializeComponent();
BindThis = new PersonView();
}
}
나는 이것을 시도하지만, 일을 해달라고 :
<CollectionViewSource x:Key="ViewPersons" Source="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=BindThis}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Name"/>
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>