SomeClassProp.SubTextProp
에 대한 바인딩이 작동하지 않습니다 (소스 속성이 텍스트 상자 내용으로 설정되지 않음). TextProp
않습니다.ElementName이 (중첩 된) 하위 속성에 대해 RelativeSource가 작동하지 않습니다.
XAML :
<Window x:Class="TestWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Name="wMain"
SizeToContent="WidthAndHeight">
<StackPanel>
<TextBox Text="{Binding ElementName=wMain, Path=SomeClassProp.SubTextProp}" Width="120" Height="23" />
<TextBox Text="{Binding ElementName=wMain, Path=TextProp}" Width="120" Height="23" />
</StackPanel>
</Window>
및 코드 :
public partial class MainWindow : Window
{
public SomeClass SomeClassProp { get; set; }
public string TextProp { get; set; }
public MainWindow()
{
InitializeComponent();
SomeClassProp = new SomeClass();
}
}
public class SomeClass
{
public string SubTextProp { get; set; }
}
내가 여기 뭔가를 분명 실종?
대상 (텍스트 상자)에서 소스 (클래스 속성)로 작업하려면이 바인딩이 필요합니다.
업데이트 : ElementName=wMain
에서 RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}
으로 바인딩을 변경할 때 - 모두 바인딩이 작동합니다. 따라서 문제는 ElementName
바인딩 속성에만 해당됩니다.
이것이 작동해야하는 이유는 경로라고 불리는 이유입니다. 출력 창에서 binf = ding 오류를 찾았습니까? 확실히 그 문자열이 전혀 설정되지 않았습니까? –
뷰 모델과 함께 작동합니까? –
출력에 바인딩 오류가 없습니다. 'SubTextProp'은 'null'로 남아있는 반면,'TextProp'은 텍스트 상자에 입력 한 것으로 설정됩니다. – lxa