2017-04-08 38 views
1

我遇到了ReactiveUI的奇怪問題,並且綁定的位置綁定在調試版本中正常工作,但在發佈版本中無法正常工作。ReactiveUI綁定無法在UWP應用程序的發佈版本中工作

在這裏,我有一個示例應用程序的代碼,顯示問題。在調試版本中,當我在文本框中輸入內容時,視圖模型中的InputText屬性會相應地更新,當我點擊按鈕時,它會在消息對話框中向我顯示更新後的輸入文本。但Release版本中的相同代碼不起作用,因爲InputText始終爲空。

任何人都知道這裏發生了什麼?

<Page x:Class="RxBind.MainPage" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <StackPanel> 
     <TextBox x:Name="MyTextBox" Margin="10"/> 
     <Button x:Name="MyButton" Content="Show Dialog" Margin="10"/> 
    </StackPanel> 
</Page> 



public sealed partial class MainPage : IViewFor<MainPageViewModel> 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 

     ViewModel = new MainPageViewModel(); 

     this.WhenActivated(d => 
     { 
      d(this.BindCommand(ViewModel, vm => vm.MyButtonCommand, v => v.MyButton)); 
      d(this.Bind(ViewModel, vm => vm.InputText, x => x.MyTextBox.Text)); 
     }); 
    } 

    #region IViewFor impl 

    object IViewFor.ViewModel 
    { 
     get { return ViewModel; } 
     set { ViewModel = (MainPageViewModel)value; } 
    } 

    public MainPageViewModel ViewModel { get; set; } 

    #endregion //IViewFor impl 
} 



public class MainPageViewModel : ReactiveObject 
{ 
    private string _inputText = string.Empty; 
    public string InputText 
    { 
     get { return _inputText; } 
     set { this.RaiseAndSetIfChanged(ref _inputText, value); } 
    } 

    public ReactiveCommand<Unit, Unit> MyButtonCommand { get; } 

    public MainPageViewModel() 
    { 
     MyButtonCommand = ReactiveCommand.CreateFromTask(async() => 
     { 
      await new MessageDialog($"InputText={InputText}").ShowAsync(); 
     }); 
    } 
} 
+0

@Sunteen Wu,你真的嘗試過上面的結論,並得出結論,它是不夠重現?上面的代碼實際上就是*我在示例項目中編碼的所有內容,而不是一行代碼。 –

+0

即使在最新的UWP和.NET Native工具上,我也能夠重現您的問題。它類似於https://github.com/reactiveui/ReactiveUI/issues/1330,我也有興趣追趕它。您可以加入討論,或通過電子郵件[email protected]向我發送電子郵件。我可能需要一兩天的時間來挖掘。 –

+0

對不起,我的錯。測試時錯過了ReactiveUI的第三方軟件包。刪除。 –

回答

0

正如Matt Whilden在this thread中提到的那樣,使用運行時指令方法解決了這個問題,所以我將其標記爲正確的答案。非常感謝Matt Whilden。

1

這是不是一個真正的回答你的問題「什麼是怎麼回事,」但我是誰提起其他錯誤馬特Whilden掛傢伙,我工作圍繞它暫時由引用按鈕事件的文本,並呼籲從那裏指揮過,而不是直接結合的命令按鈕,有點像這樣:

d(Observable.FromEventPattern<RoutedEventHandler, object, RoutedEventArgs>(h => MyButton.Click += h, h => MyButton.Click -= h).Subscribe(x=> 
{ 
    ViewModel.InputText = MyTextBox.Text; 
    ViewModel.MyButtonCommand.Execute(null); 
})); 

不優雅,但它爲我工作,因爲我並不真的需要更新屬性更改 - 只需點擊按鈕。在問題解決之前,這也許會對你有用。

+0

Execute中的null是虛假的,但這確實解決了報告的問題。我會繼續挖掘。我的調查筆記將在GitHub主題中。 –

相關問題