2017-12-30 90 views
0

INotifyPropertyChanged을 구현하는 ContentDialog이 있습니다. 문자의 x:Bind 구문을 통해 내 코드 숨김의 문자열 속성에 바인딩 된 Text 속성을 가진 TextBox이 있습니다.ContentDialog 및 x와 관련된 문제 : Bind

나는 TextBox의 내용을 편집 한 다음 ContentDialog합니다 (TextBox에 손실 초점)에서 다른 컨트롤을 클릭 한 다음 나는 차 버튼 클릭 이벤트 처리기에 도착하는 시간에 의해, 기본 버튼을 클릭하면 텍스트 속성이 TextBox control = PERFECT의 내용으로 업데이트되었습니다.

그러나 TextBox의 내용을 변경했지만 초점을 유지 한 채 기본 단추를 클릭하면 바인딩이 업데이트되지 않습니다.

이것에 대한 이유는 것 같다 때문에 내장 ContentDialog의 버튼들이 클릭 eventhandlers이 발사되기 전에 초점을 취득하지 않으며, x:Bind 만 바인딩 LostFocus을 지원하는, 이러한 바인딩이 업데이트되지 않습니다.

나는이 큰 버그가 존재한다는 것을 비웃었습니다. 그래서 내 2 개 질문

1) 해결

2) 나는 내가 바인딩 자체 내에서 UpdateSourceTrigger을 변경할 수있는, WPF 스타일을 Binding 구문을 x:Bind을 포기하고 사용해야합니까가 있습니다.

내가 다른 UWP dev에이 건너와

편집

주위에 작업을 알고 것을 바라고 있어요 필자는이 문제를 설명하는 몇 가지 예제 코드를 만들었습니다.

페이지 :

<Page 
    x:Class="App1.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:App1" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     <Button Content="Open" Click="OpenClick" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
    </Grid> 
</Page> 

코드 숨김

public sealed partial class MainPage : Page 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    private async void OpenClick(object sender, RoutedEventArgs e) 
    { 
     var dialog = new ContentDialog1(); 
     await dialog.ShowAsync(); 
    } 
} 

내용의 대화 : 뒤에

<ContentDialog 
    x:Class="App1.ContentDialog1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    Title="TITLE" 
    PrimaryButtonText="Button1" 
    PrimaryButtonClick="ContentDialog_PrimaryButtonClick"> 

    <Grid> 
     <TextBox Text="{x:Bind Path=TestText, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="100"/> 
    </Grid> 
</ContentDialog> 

콘텐츠 대화 코드 :

public sealed partial class ContentDialog1 : ContentDialog, INotifyPropertyChanged 
{ 
    public ContentDialog1() 
    { 
     InitializeComponent(); 
    } 

    private string _testText; 
    public string TestText 
    { 
     get => _testText; 
     set 
     { 
      _testText = value; 
      OnPropertyChanged(nameof(TestText)); 
     } 
    } 

    private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) 
    { 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    private void OnPropertyChanged(string propertyName = null) 
    { 
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
    } 
} 
012 3,516,

그리고 내 목표 SDK verions은 다음과 같습니다 당신은 내용의 대화 상자를 열려면 시작을 클릭하면

enter image description here

는 다음 기본 단추를 클릭 텍스트를 입력 - 당신은 클릭 처리기에 중단 점을 경우 당신은 것을 볼 수 있습니다 입력 한 텍스트로 바인딩이 업데이트되지 않았습니다.

답변

0

확인,이 살펴본 TextBox이 업데이트의 바인딩 순서에 초점을 잃을 필요하기 때문에, 10586.는 기본적으로 ContentDialogTextBoxx:Bind 바인딩에 대한 고장 구축하기 위해 모든 SDK의 뒷면에이를 테스트했습니다. 나는 시각적 트리를 걸어서 Loaded에있는 숨겨진 버튼에 별도의 핸들러를 추가하고 클릭 처리기가 실행되기 전에 포커스를 강제로 (따라서 모든 TextBox에서 포커스를 제거하고 바인딩 업데이트를 트리거하도록) 시도하는 등 여러 가지 해킹을 시도했습니다 UWP가 터널링 이벤트 전략 (예 : WPF)을 지원하지 않으면 버튼 누르기와 실행중인 고정 클릭 클릭 핸들러 사이에 어떤 종류의 이벤트 처리도 주입 할 수 없습니다. 결과는 x:Bind (UpdateSourceTriggerLostFocus 이외의 것을 지원하지 않음)이 TextBox 컨트롤로 안정적으로 작동하지 않음을 나타냅니다.

Microsoft uservoice에서 버그를 기록했습니다. 따라서 클릭에서 바인딩이 최대 최신 버튼을하기 전에 항상 허용 -

이 문제를 해결하는 유일한 방법은 x:Bind을 포기하고 UpdateSourceTriggerPropertyChanged의를 지원하는 고전적인 바인딩을 사용하는 것입니다. UpdateSourceTriggerPropertyChanged 인 경우 설정자가 불필요한 업데이트를 유발할 수 있기 때문에 해킹 일지라도 문제가 될 수 있습니다. 또한 설정자를 INotifyPropertyChanged으로 업데이트하면 모든 레이아웃에 대해 정렬/측정 값 패스가 추가로 실행됩니다.

유일한 해결책은 자신의 ContentDialog 컨트롤을 작성하는 것입니다. 나는이 일을하고 싶지만 이러한 컨트롤에 대한 Microsoft 소스 코드에 액세스하지 않으면 성공적으로 수행했는지 알기가 어렵습니다.

0

포커스가 여전히있는 상태에서 기본 버튼을 클릭하더라도 코드 숨김에서 string 속성이 항상 ContentDialog_PrimaryButtonClick보다 먼저 발생합니다. 문제가 재현되지 않습니다. TextBox에 있습니다. 내 샘플 (Fall Creators 업데이트 테스트 완료) :

MyContentDialogXAML

<Grid> 
    <TextBox Text="{x:Bind MyString, Mode=TwoWay}"/> 
</Grid> 

MyContentDialog.xaml.cs

public sealed partial class MyContentDialog : ContentDialog, INotifyPropertyChanged 
{ 
    private DTO dto; 

    private string myString; 
    public string MyString 
    { 
     get 
     { 
      return myString; 
     } 
     set 
     { 
      myString = value; 
      NotifyPropertyChanged(nameof(MyString)); 
     } 
    } 

    public MyContentDialog(DTO dto) 
    { 
     this.InitializeComponent(); 

     this.dto = dto; 
     MyString = dto.text; 
    } 


    private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) 
    { 
     dto.text = MyString; 
    } 

    private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) 
    { 
    } 


    public event PropertyChangedEventHandler PropertyChanged; 
    private void NotifyPropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
    } 
} 

DTO.cs

public class DTO 
{ 
    public string text; 
} 

MainPage.xaml.cs를

private async void Page_Loaded(object sender, RoutedEventArgs e) 
{ 
    DTO dto = new DTO { text = "My text" }; 

    MyContentDialog dialog = new MyContentDialog(dto); 
    await dialog.ShowAsync(); 

    await new MessageDialog("My text, after being edited by the user in MyContentDialog: " + dto.text).ShowAsync(); 
} 

코드를 공유 할 수 있습니까? 프로젝트의 최소 및 타겟 버전은 무엇입니까?

+0

도움을 주셔서 감사합니다. 이 문제점을 보여주는 내 코드 버전을 만들고 대상 SDK 정보를 포함 시켰습니다. –