사용자 지정 컨트롤의 종속성 속성에 FindAncestor 바인딩은 DependencyProperty MyString의WPF 내가 가진 사용자 정의 WPF 컨트롤을 가지고
내가보기에 ItemsControl에 내 컨트롤을 사용하여으로부터 값을 물고기 싶어 해요 ViewModel
컨트롤의 DataContext는 ItemsControl의 ItemsSource에서 각 항목이 될 때마다 FindAncestor를 사용할 수 있다고 생각했지만 dosnt가 작동하는 것처럼 보였습니다 ... 누군가 내가 잘못 가고있는 것을 볼 수 있습니까?
보기에을 heres XAML ...
<Grid>
<ItemsControl ItemsSource="{Binding MyItems}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Name="myStack">
<ImportExceptions:ControlStrip MyString="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.MyStringOnViewModel}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
및
을 heres 내 종속성 속성을 설정 한 내 사용자 지정 컨트롤 뒤에 코드 ...의public partial class ControlStrip
{
public ControlStrip()
{
InitializeComponent();
}
public string MyString
{
get
{
return GetValue(MyStringProperty).ToString();
}
set
{
SetValue(MyStringProperty, value);
}
}
public static readonly DependencyProperty MyStringProperty =
DependencyProperty.RegisterAttached("MyString", typeof (string), typeof (ControlStrip));
}
나는 그것이 넥타이라고 생각 했는가? ;) – kiwipom
DataContext 참조에서 오류가 발견 된 것으로 의심됩니다. 당신의 도움을 주셔서 감사합니다 –