나는 Binding
개체를 가지고 있는데,이 Binding
의 부모를 알고 싶습니다.바인딩 부모님
예 : Binding
의
<Label Name="BindingLabel" Content="{Binding Path=LabelText}"/>
예에서 부모가 이름 BindingLabel와 Label
하고 난 단지 Binding
객체에서 얻을 수있는 방법을 검색 할 수 있습니다.
감사합니다.
나는 Binding
개체를 가지고 있는데,이 Binding
의 부모를 알고 싶습니다.바인딩 부모님
예 : Binding
의
<Label Name="BindingLabel" Content="{Binding Path=LabelText}"/>
예에서 부모가 이름 BindingLabel와 Label
하고 난 단지 Binding
객체에서 얻을 수있는 방법을 검색 할 수 있습니다.
감사합니다.
Binding
은 여러 개체에서 사용할 수 있으므로 Parent
은 사용할 수 없습니다. 찾고있는 객체 (예 : 이미 목록이 있거나 트리를 걸을 수 있음)와 확인할 종속성 속성을 알고 있으면 요소가 해당 바인딩을 사용하는지 확인할 수 있습니다.
var path = "LabelText";
IEnumerable<Label> labels = // whatever
foreach (var label in labels)
{
if (label.GetBindingExpression(Label.ContentProperty).ParentBinding.Path.Path
== path)
{
// found it!
}
}
귀하의 질문은 벽돌 쌓는 모호 :
Binding binding = // whatever (must be the same instance used in the object)
IEnumerable<Label> labels = // whatever
foreach (var label in labels)
{
if (label.GetBindingExpression(Label.ContentProperty).ParentBinding
== binding)
{
// found it!
}
}
또는 어쩌면 당신은 그냥 경로를 비교할 : 여기
당신이 사용되는 Binding
의 정확한 인스턴스가있는 경우 그렇게 할 수있는 방법 왜냐하면 당신이 그걸로 무엇을 하려는지 설명하지 않기 때문입니다. 레이블의 특정 속성을 설정하려면 valueconverter를 사용할 수 있습니다. 또한 당신은 내가 코드 그래서 난 바인딩 선언이나 뭔가 떨어져있을 수 있습니다 테스트하지 않았다
<Label>
<Label.Content>
<MultiBinding Converter="{StaticResource MyConverter}">
<MultiBinding.Bindings>
<Binding Path="LabelText" />
<Binding RelativeSource="{RelativeSource Self}"/>
</MultiBinding.Bindings>
</MultiBinding>
</Label.Content>
</Label>
바인딩 (다)에서 RelativeSource = 자기를 사용하여 객체 자체에 대한 참조를 전달할 수 있습니다.
지금은 그런 식으로 진행하지만 모든 개체를 모른 채 찾을 수있는 방법을 찾고 있습니다. – igofed