Browse Source

Add demo of binding to array index.

Tried to add a button to shuffle ObservableCollection, but Command binding doesn't seem to work.
pull/237/head
Steven Kirk 11 years ago
parent
commit
0c837f87a8
  1. 1
      samples/BindingTest/App.cs
  2. 17
      samples/BindingTest/BindingTest.csproj
  3. 18
      samples/BindingTest/MainWindow.paml
  4. 24
      samples/BindingTest/ViewModels/MainWindowViewModel.cs
  5. 15
      samples/BindingTest/ViewModels/TestItem.cs
  6. 5
      samples/BindingTest/packages.config
  7. 2
      src/Markup/Perspex.Markup.Xaml/OmniXAML
  8. 2
      src/Perspex.Base/PerspexObject.cs

1
samples/BindingTest/App.cs

@ -18,7 +18,6 @@ namespace BindingTest
Log.Logger = new LoggerConfiguration()
.Filter.ByIncludingOnly(Matching.WithProperty("Area", "Property"))
.Filter.ByIncludingOnly(Matching.WithProperty<string>("Property", x => x == "Text"))
.MinimumLevel.Verbose()
.WriteTo.Trace(outputTemplate: "[{Id:X8}] [{SourceContext}] {Message}")
.CreateLogger();

17
samples/BindingTest/BindingTest.csproj

@ -50,6 +50,22 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Rx-Core.2.2.5\lib\net45\System.Reactive.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Reactive.Interfaces, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Rx-Interfaces.2.2.5\lib\net45\System.Reactive.Interfaces.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Reactive.Linq, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Rx-Linq.2.2.5\lib\net45\System.Reactive.Linq.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Reactive.PlatformServices, Version=2.2.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Rx-PlatformServices.2.2.5\lib\net45\System.Reactive.PlatformServices.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
@ -64,6 +80,7 @@
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\MainWindowViewModel.cs" />
<Compile Include="ViewModels\TestItem.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

18
samples/BindingTest/MainWindow.paml

@ -1,9 +1,15 @@
<Window xmlns="https://github.com/perspex">
<StackPanel Margin="18" Gap="4">
<TextBlock Text="{Binding SimpleBinding}"/>
<TextBox Watermark="Two Way" UseFloatingWatermark="True" Text="{Binding SimpleBinding}"/>
<TextBox Watermark="One Way" UseFloatingWatermark="True" Text="{Binding SimpleBinding, Mode=OneWay}"/>
<TextBox Watermark="One Time" UseFloatingWatermark="True" Text="{Binding SimpleBinding, Mode=OneTime}"/>
<TextBox Watermark="One Way To Source" UseFloatingWatermark="True" Text="{Binding SimpleBinding, Mode=OneWayToSource}"/>
<StackPanel Orientation="Horizontal">
<StackPanel Margin="18" Gap="4" Width="200">
<TextBlock Text="{Binding SimpleBinding}"/>
<TextBox Watermark="Two Way" UseFloatingWatermark="True" Text="{Binding SimpleBinding}"/>
<TextBox Watermark="One Way" UseFloatingWatermark="True" Text="{Binding SimpleBinding, Mode=OneWay}"/>
<TextBox Watermark="One Time" UseFloatingWatermark="True" Text="{Binding SimpleBinding, Mode=OneTime}"/>
<TextBox Watermark="One Way To Source" UseFloatingWatermark="True" Text="{Binding SimpleBinding, Mode=OneWayToSource}"/>
</StackPanel>
<StackPanel Margin="18" Gap="4" Width="200">
<TextBox Watermark="Items[1].StringValue" UseFloatingWatermark="True" Text="{Binding Items[1].StringValue}"/>
<Button Command="{Binding ShuffleItems}">Shuffle</Button>
</StackPanel>
</StackPanel>
</Window>

24
samples/BindingTest/ViewModels/MainWindowViewModel.cs

@ -1,4 +1,6 @@
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using ReactiveUI;
namespace BindingTest.ViewModels
{
@ -6,6 +8,26 @@ namespace BindingTest.ViewModels
{
private string _simpleBinding = "Simple Binding";
public MainWindowViewModel()
{
Items = new ObservableCollection<TestItem>
{
new TestItem { StringValue = "Foo" },
new TestItem { StringValue = "Bar" },
new TestItem { StringValue = "Baz" },
};
ShuffleItems = ReactiveCommand.Create();
ShuffleItems.Subscribe(_ =>
{
var r = new Random();
Items[r.Next(Items.Count)] = Items[r.Next(Items.Count)];
});
}
public ObservableCollection<TestItem> Items { get; }
public ReactiveCommand<object> ShuffleItems { get; }
public string SimpleBinding
{
get { return _simpleBinding; }

15
samples/BindingTest/ViewModels/TestItem.cs

@ -0,0 +1,15 @@
using ReactiveUI;
namespace BindingTest.ViewModels
{
public class TestItem : ReactiveObject
{
private string stringValue = "String Value";
public string StringValue
{
get { return stringValue; }
set { this.RaiseAndSetIfChanged(ref this.stringValue, value); }
}
}
}

5
samples/BindingTest/packages.config

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Rx-Core" version="2.2.5" targetFramework="net46" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net46" />
<package id="Rx-Linq" version="2.2.5" targetFramework="net46" />
<package id="Rx-Main" version="2.2.5" targetFramework="net46" />
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="net46" />
<package id="Serilog" version="1.5.9" targetFramework="net46" />
<package id="Splat" version="1.6.2" targetFramework="net46" />
</packages>

2
src/Markup/Perspex.Markup.Xaml/OmniXAML

@ -1 +1 @@
Subproject commit 49e6ec001f5873cf2290e0bc1f6f06ca9b9cf808
Subproject commit c890902fbaecb4752ed8e9fde2571396794fe06d

2
src/Perspex.Base/PerspexObject.cs

@ -187,7 +187,7 @@ namespace Perspex
if (sourceBinding == null && mode > BindingMode.OneWay)
{
throw new InvalidOperationException("Can only bind OneWay to plain IObservable.");
mode = BindingMode.OneWay;
}
switch (mode)

Loading…
Cancel
Save