Skip to content

Commit 8370907

Browse files
author
Paul Betts
committed
Merge pull request #487 from reactiveui/blend-win81
ReactiveUI.Blend for Windows 8.1.
2 parents 9c26105 + f62b1d8 commit 8370907

File tree

7 files changed

+369
-34
lines changed

7 files changed

+369
-34
lines changed

ReactiveUI.Blend/Behavior.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Windows.UI.Xaml;
2+
using Microsoft.Xaml.Interactivity;
3+
using Windows.ApplicationModel;
4+
using System;
5+
6+
namespace ReactiveUI.Blend
7+
{
8+
public class Behavior<T> : DependencyObject, IBehavior where T: DependencyObject
9+
{
10+
public virtual void Attach(DependencyObject associatedObject)
11+
{
12+
if (associatedObject == this.AssociatedObject || DesignMode.DesignModeEnabled) {
13+
return;
14+
}
15+
16+
if (this.AssociatedObject != null) {
17+
throw new InvalidOperationException("Cannot attach multiple objects.");
18+
}
19+
20+
AssociatedObject = associatedObject as T;
21+
OnAttached();
22+
}
23+
24+
public virtual void Detach()
25+
{
26+
OnDetaching();
27+
}
28+
29+
protected virtual void OnAttached()
30+
{
31+
}
32+
33+
protected virtual void OnDetaching()
34+
{
35+
}
36+
37+
public T AssociatedObject { get; private set; }
38+
39+
DependencyObject IBehavior.AssociatedObject {
40+
get { return this.AssociatedObject; }
41+
}
42+
}
43+
}

ReactiveUI.Blend/FollowObservableStateBehavior.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Reactive.Linq;
45
using System.Text;
6+
7+
#if !WINRT
58
using System.Windows;
6-
using System.Windows.Controls;
7-
using System.Windows.Data;
8-
using System.Windows.Documents;
9-
using System.Windows.Input;
10-
using System.Windows.Media;
11-
using System.Windows.Media.Imaging;
12-
using System.Windows.Shapes;
139
using System.Windows.Interactivity;
14-
using System.Linq;
15-
//using Microsoft.Expression.Interactivity.Core;
10+
using System.Windows.Controls;
11+
#else
12+
using Windows.UI.Xaml;
13+
using Windows.UI.Xaml.Controls;
14+
#endif
1615

1716
namespace ReactiveUI.Blend
1817
{
19-
#if SILVERLIGHT
18+
#if SILVERLIGHT || WINRT
2019
public class FollowObservableStateBehavior : Behavior<Control>
2120
#else
2221
public class FollowObservableStateBehavior : Behavior<FrameworkElement>
@@ -27,9 +26,9 @@ public IObservable<string> StateObservable {
2726
set { SetValue(StateObservableProperty, value); }
2827
}
2928
public static readonly DependencyProperty StateObservableProperty =
30-
DependencyProperty.Register("StateObservable", typeof(IObservable<string>), typeof(FollowObservableStateBehavior), new PropertyMetadata(onStateObservableChanged));
29+
DependencyProperty.Register("StateObservable", typeof(IObservable<string>), typeof(FollowObservableStateBehavior), new PropertyMetadata(null, onStateObservableChanged));
3130

32-
#if SILVERLIGHT
31+
#if SILVERLIGHT || WINRT
3332
public Control TargetObject {
3433
get { return (Control)GetValue(TargetObjectProperty); }
3534
set { SetValue(TargetObjectProperty, value); }
@@ -69,7 +68,7 @@ protected static void onStateObservableChanged(DependencyObject sender, Dependen
6968
This.watcher = ((IObservable<string>)e.NewValue).ObserveOn(RxApp.MainThreadScheduler).Subscribe(
7069
x => {
7170
var target = This.TargetObject ?? This.AssociatedObject;
72-
#if SILVERLIGHT
71+
#if SILVERLIGHT || WINRT
7372
VisualStateManager.GoToState(target, x, true);
7473
#else
7574
if (target is Control) {
@@ -86,4 +85,4 @@ protected static void onStateObservableChanged(DependencyObject sender, Dependen
8685
});
8786
}
8887
}
89-
}
88+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reactive.Disposables;
5+
using System.Reactive.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using Microsoft.Xaml.Interactivity;
9+
using Windows.UI.Xaml;
10+
using Windows.UI.Xaml.Markup;
11+
12+
namespace ReactiveUI.Blend
13+
{
14+
[ContentProperty(Name = "Actions")]
15+
public sealed class ObservableTriggerBehavior : Behavior<DependencyObject>
16+
{
17+
object resolvedSource;
18+
SerialDisposable watcher;
19+
20+
public ObservableTriggerBehavior()
21+
{
22+
watcher = new SerialDisposable();
23+
watcher.Disposable = Disposable.Empty;
24+
}
25+
26+
public ActionCollection Actions
27+
{
28+
get {
29+
var actionCollection = (ActionCollection) this.GetValue(ObservableTriggerBehavior.ActionsProperty);
30+
31+
if (actionCollection == null) {
32+
actionCollection = new ActionCollection();
33+
this.SetValue(ObservableTriggerBehavior.ActionsProperty, actionCollection);
34+
}
35+
36+
return actionCollection;
37+
}
38+
}
39+
40+
public static readonly DependencyProperty ActionsProperty =
41+
DependencyProperty.Register("Actions", typeof(ActionCollection), typeof(ObservableTriggerBehavior), new PropertyMetadata(null));
42+
43+
public object SourceObject {
44+
get { return this.GetValue(ObservableTriggerBehavior.SourceObjectProperty); }
45+
set { this.SetValue(ObservableTriggerBehavior.SourceObjectProperty, value); }
46+
}
47+
public static readonly DependencyProperty SourceObjectProperty =
48+
DependencyProperty.Register("SourceObject", typeof(object), typeof(ObservableTriggerBehavior), new PropertyMetadata(null, OnSourceObjectChanged));
49+
50+
public bool AutoResubscribeOnError { get; set; }
51+
52+
public IObservable<object> Observable {
53+
get { return (IObservable<object>)GetValue(ObservableProperty); }
54+
set { SetValue(ObservableProperty, value); }
55+
}
56+
public static readonly DependencyProperty ObservableProperty =
57+
DependencyProperty.Register("Observable", typeof(IObservable<object>), typeof(ObservableTriggerBehavior), new PropertyMetadata(null, onObservableChanged));
58+
59+
static void OnSourceObjectChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
60+
{
61+
var observableTriggerBehavior = (ObservableTriggerBehavior)dependencyObject;
62+
63+
observableTriggerBehavior.setResolvedSource(observableTriggerBehavior.computeResolvedSource());
64+
}
65+
66+
void setResolvedSource(object newSource)
67+
{
68+
if (this.AssociatedObject == null || this.resolvedSource == newSource) {
69+
return;
70+
}
71+
72+
this.resolvedSource = newSource;
73+
}
74+
75+
object computeResolvedSource()
76+
{
77+
if (this.ReadLocalValue(ObservableTriggerBehavior.SourceObjectProperty) != DependencyProperty.UnsetValue) {
78+
return this.SourceObject;
79+
} else {
80+
return this.AssociatedObject;
81+
}
82+
}
83+
84+
static void onObservableChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
85+
{
86+
ObservableTriggerBehavior This = (ObservableTriggerBehavior)sender;
87+
88+
This.watcher.Disposable = ((IObservable<object>)e.NewValue).ObserveOn(RxApp.MainThreadScheduler).Subscribe(
89+
x => Interaction.ExecuteActions(This.resolvedSource, This.Actions, x),
90+
ex =>
91+
{
92+
if (!This.AutoResubscribeOnError)
93+
return;
94+
onObservableChanged(This, e);
95+
});
96+
}
97+
98+
protected override void OnAttached()
99+
{
100+
base.OnAttached();
101+
this.setResolvedSource(this.computeResolvedSource());
102+
}
103+
104+
protected override void OnDetaching()
105+
{
106+
this.setResolvedSource(null);
107+
base.OnDetaching();
108+
109+
watcher.Dispose();
110+
}
111+
}
112+
}

ReactiveUI.Blend/ReactiveUI.Blend_WP8.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
<Compile Include="Properties\AssemblyInfo.cs" />
123123
</ItemGroup>
124124
<ItemGroup>
125-
<None Include="app.config" />
126125
<ProjectReference Include="..\ReactiveUI\ReactiveUI.csproj">
127126
<Project>{464CB812-F99F-401B-BE4C-E8F0515CD19D}</Project>
128127
<Name>ReactiveUI</Name>
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProductVersion>8.0.30703</ProductVersion>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{14AE16FF-E9A7-4AB1-BCBB-3B2B2049288D}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>ReactiveUI.Blend</RootNamespace>
13+
<AssemblyName>ReactiveUI.Blend</AssemblyName>
14+
<DefaultLanguage>en-US</DefaultLanguage>
15+
<TargetPlatformVersion>8.1</TargetPlatformVersion>
16+
<MinimumVisualStudioVersion>12</MinimumVisualStudioVersion>
17+
<FileAlignment>512</FileAlignment>
18+
<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\WinRT451\</OutputPath>
25+
<DefineConstants>TRACE;DEBUG;WINRT</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\WinRT451\</OutputPath>
33+
<DefineConstants>TRACE;WINRT</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
<DocumentationFile>bin\Release\WinRT451\ReactiveUI.Blend.xml</DocumentationFile>
37+
</PropertyGroup>
38+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
39+
<DebugSymbols>true</DebugSymbols>
40+
<OutputPath>bin\ARM\Debug\</OutputPath>
41+
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
42+
<NoWarn>;2008</NoWarn>
43+
<DebugType>full</DebugType>
44+
<PlatformTarget>ARM</PlatformTarget>
45+
<UseVSHostingProcess>false</UseVSHostingProcess>
46+
<ErrorReport>prompt</ErrorReport>
47+
<Prefer32Bit>true</Prefer32Bit>
48+
</PropertyGroup>
49+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
50+
<OutputPath>bin\ARM\Release\</OutputPath>
51+
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
52+
<Optimize>true</Optimize>
53+
<NoWarn>;2008</NoWarn>
54+
<DebugType>pdbonly</DebugType>
55+
<PlatformTarget>ARM</PlatformTarget>
56+
<UseVSHostingProcess>false</UseVSHostingProcess>
57+
<ErrorReport>prompt</ErrorReport>
58+
<Prefer32Bit>true</Prefer32Bit>
59+
</PropertyGroup>
60+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
61+
<DebugSymbols>true</DebugSymbols>
62+
<OutputPath>bin\x64\Debug\</OutputPath>
63+
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
64+
<NoWarn>;2008</NoWarn>
65+
<DebugType>full</DebugType>
66+
<PlatformTarget>x64</PlatformTarget>
67+
<UseVSHostingProcess>false</UseVSHostingProcess>
68+
<ErrorReport>prompt</ErrorReport>
69+
<Prefer32Bit>true</Prefer32Bit>
70+
</PropertyGroup>
71+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
72+
<OutputPath>bin\x64\Release\</OutputPath>
73+
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
74+
<Optimize>true</Optimize>
75+
<NoWarn>;2008</NoWarn>
76+
<DebugType>pdbonly</DebugType>
77+
<PlatformTarget>x64</PlatformTarget>
78+
<UseVSHostingProcess>false</UseVSHostingProcess>
79+
<ErrorReport>prompt</ErrorReport>
80+
<Prefer32Bit>true</Prefer32Bit>
81+
</PropertyGroup>
82+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
83+
<DebugSymbols>true</DebugSymbols>
84+
<OutputPath>bin\x86\Debug\</OutputPath>
85+
<DefineConstants>DEBUG;TRACE;NETFX_CORE</DefineConstants>
86+
<NoWarn>;2008</NoWarn>
87+
<DebugType>full</DebugType>
88+
<PlatformTarget>x86</PlatformTarget>
89+
<UseVSHostingProcess>false</UseVSHostingProcess>
90+
<ErrorReport>prompt</ErrorReport>
91+
<Prefer32Bit>true</Prefer32Bit>
92+
</PropertyGroup>
93+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
94+
<OutputPath>bin\x86\Release\</OutputPath>
95+
<DefineConstants>TRACE;NETFX_CORE</DefineConstants>
96+
<Optimize>true</Optimize>
97+
<NoWarn>;2008</NoWarn>
98+
<DebugType>pdbonly</DebugType>
99+
<PlatformTarget>x86</PlatformTarget>
100+
<UseVSHostingProcess>false</UseVSHostingProcess>
101+
<ErrorReport>prompt</ErrorReport>
102+
<Prefer32Bit>true</Prefer32Bit>
103+
</PropertyGroup>
104+
<ItemGroup>
105+
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
106+
<None Include="packages.config" />
107+
</ItemGroup>
108+
<ItemGroup>
109+
<Compile Include="Behavior.cs" />
110+
<Compile Include="FollowObservableStateBehavior.cs" />
111+
<Compile Include="ObservableTriggerBehavior.cs" />
112+
<Compile Include="Properties\AssemblyInfo.cs" />
113+
</ItemGroup>
114+
<ItemGroup>
115+
<SDKReference Include="BehaviorsXamlSDKManaged, Version=12.0">
116+
<Name>Behaviors SDK %28XAML%29</Name>
117+
</SDKReference>
118+
</ItemGroup>
119+
<ItemGroup>
120+
<Reference Include="Splat">
121+
<HintPath>..\ext\winrt\Splat.dll</HintPath>
122+
</Reference>
123+
<Reference Include="System.Reactive.Core">
124+
<HintPath>..\ext\winrt\System.Reactive.Core.dll</HintPath>
125+
</Reference>
126+
<Reference Include="System.Reactive.Interfaces">
127+
<HintPath>..\ext\winrt\System.Reactive.Interfaces.dll</HintPath>
128+
</Reference>
129+
<Reference Include="System.Reactive.Linq">
130+
<HintPath>..\ext\winrt\System.Reactive.Linq.dll</HintPath>
131+
</Reference>
132+
<Reference Include="System.Reactive.PlatformServices">
133+
<HintPath>..\ext\winrt\System.Reactive.PlatformServices.dll</HintPath>
134+
</Reference>
135+
<Reference Include="System.Reactive.Windows.Threading">
136+
<HintPath>..\ext\winrt\System.Reactive.Windows.Threading.dll</HintPath>
137+
</Reference>
138+
<Reference Include="System.Reactive.WindowsRuntime">
139+
<HintPath>..\ext\winrt\System.Reactive.WindowsRuntime.dll</HintPath>
140+
</Reference>
141+
</ItemGroup>
142+
<ItemGroup>
143+
<ProjectReference Include="..\ReactiveUI\ReactiveUI.csproj">
144+
<Project>{464cb812-f99f-401b-be4c-e8f0515cd19d}</Project>
145+
<Name>ReactiveUI</Name>
146+
</ProjectReference>
147+
</ItemGroup>
148+
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
149+
<VisualStudioVersion>12.0</VisualStudioVersion>
150+
</PropertyGroup>
151+
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
152+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
153+
Other similar extension points exist, see Microsoft.Common.targets.
154+
<Target Name="BeforeBuild">
155+
</Target>
156+
<Target Name="AfterBuild">
157+
</Target>
158+
-->
159+
</Project>

0 commit comments

Comments
 (0)