Forráskód Böngészése

Change the observable stream binding in BindingDemo to be a compiled binding.

Jeremy Koritzinsky 6 éve
szülő
commit
b173d5b5fb

+ 3 - 2
samples/BindingDemo/MainWindow.xaml

@@ -5,7 +5,8 @@
         xmlns:local="clr-namespace:BindingDemo"
         Title="AvaloniaUI Bindings Test"
         Width="800"
-        Height="600">
+        Height="600"
+        x:DataContextType="{x:Type vm:MainWindowViewModel}">
   <Window.Styles>
     <Style Selector="TextBlock.h1">
       <Setter Property="FontSize" Value="18"/>
@@ -57,7 +58,7 @@
             <TextBlock FontSize="16" Text="Scheduler"/>
             <TextBox Watermark="Background Thread" Text="{Binding CurrentTime, Mode=OneWay}"/>
             <TextBlock FontSize="16" Text="Stream Operator"/>
-            <TextBox Watermark="StreamOperator" Text="{Binding CurrentTimeObservable^, Mode=OneWay}"/>
+            <TextBox Watermark="StreamOperator" Text="{CompiledBinding CurrentTimeObservable^, Mode=OneWay}"/>
           </StackPanel>
         </StackPanel>
       </StackPanel>

+ 2 - 2
samples/BindingDemo/ViewModels/MainWindowViewModel.cs

@@ -51,7 +51,7 @@ namespace BindingDemo.ViewModels
             });
 
             CurrentTimeObservable = Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1))
-                .Select(x => DateTimeOffset.Now.ToString());
+                .Select(x => DateTimeOffset.Now);
         }
 
         public ObservableCollection<TestItem> Items { get; }
@@ -88,7 +88,7 @@ namespace BindingDemo.ViewModels
             private set { this.RaiseAndSetIfChanged(ref _currentTime, value); }
         }
 
-        public IObservable<string> CurrentTimeObservable { get; }
+        public IObservable<DateTimeOffset> CurrentTimeObservable { get; }
         public ReactiveCommand StringValueCommand { get; }
 
         public DataAnnotationsErrorViewModel DataAnnotationsValidation { get; } = new DataAnnotationsErrorViewModel();