파일을 "찾아보기"할 사용자 정의 컨트롤을 만들었습니다.이 컨트롤은 기본적으로 하나의 텍스트 상자와 하나의 단추로 구성됩니다.WPF : 내 사용자 지정 컨트롤에 바인딩이 업데이트되지 않습니다.
그것은 몇 가지 특성을 가지고 나를 디렉토리, 기존 (파일 열기 대화 상자) 또는 inexisting 파일 (파일 저장 대화 상자), 지정 필터 중 하나를 선택할 수 있도록 ...
나는 종속성 속성을 사용하고 있습니다 이런 식으로 내보기에서
public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register(
"FilePath",
typeof(String),
typeof(BrowseFileControl),
new PropertyMetadata(default(String), InvokeFilePathChanged)
);
public String FilePath { get { return (String)GetValue(FilePathProperty); } set { SetValue(FilePathProperty, value); } }
private static void InvokeFilePathChanged(DependencyObject property, DependencyPropertyChangedEventArgs args)
{
BrowseFileControl view = (BrowseFileControl)property;
view.InvokeFilePathChanged((String)args.OldValue, (String)args.NewValue);
}
protected virtual void InvokeFilePathChanged(String oldValue, String newValue)
{
InvokePropertyChanged("FilePath");
}
, 저는 제가 편집 할 "구성"을 선택 할 수 있도록 목록 상자를했습니다, 그리고 (내 UserControl을 포함) 내 모든 필드는 CurrentConfiguration에 바인딩 (그리고 CurrentConfiguration입니다 SelectedItem에 바인딩 됨).
내 문제 : 첫 번째로드는 항상 정상이지만 다른 구성을 선택하면 이전 텍스트가 업데이트되고 유지되지 않습니다. 내 바인딩
은 다음과 같이이다 :
<userContols:BrowseFileControl Grid.Row="4" Grid.Column="1"
Margin="2" FilePath="{Binding CurrentConfiguration.TagListFile,
ValidatesOnDataErrors=true, NotifyOnValidationError=true}"
IsFolder="False" Filter="All files (*.*)|*.*" CanBeInexistantFile="False"/>
내가 함께 간단한 텍스트 상자를 사용하는 경우 동일한 바인딩이 제대로 업데이트됩니다!
<TextBox Grid.Row="4" Grid.Column="1"
Text="{Binding CurrentConfiguration.TagListFile,ValidatesOnDataErrors=true, NotifyOnValidationError=true}"
Margin="2"/>
Visual Studio의 출력 창에는 바인딩 오류가 표시되지 않습니다.
내 바인딩에 문제가있을 수 있습니까?
편집 : 해당 UserControl의 XAML :
<Grid DataContext="{Binding ElementName=uxBrowseFileControl}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Padding="2" Text="{Binding FilePath, ValidatesOnDataErrors=true, NotifyOnValidationError=true}"/>
<Button Content="Browse" Grid.Column="1" Padding="2" Command="{Binding BrowseCommand}"/>
</Grid>
uxBrowseFileControl는 <UserControl>
편집 2의 이름입니다 : 내가 UserControl을 통해 무엇인가를 변경하면 사실은 복제되지 않는다 또한 모델 :/
Edit3 : "Mode = TwoWay"를 myItem.FilePath-> UserControl의 바인딩에 넣었지만 지금은 작동하는 것처럼 보이지만 그 이유는 무엇입니까? 같은 바인딩이있는 TextBox가 작동했습니다!
사용자 정의 컨트롤의 특정 부분은 어떻게 보이나요? – dowhilefor
@dowhilefor 내 질문을 업데이트했습니다. 원하는 내용입니까? – J4N