├── Animation.gif ├── LICENSE ├── ParallaxEffect.sln ├── ParallaxEffect ├── Parallax.cs ├── ParallaxDirection.cs ├── ParallaxEffect.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── ParallaxEffectDemo ├── App.config ├── App.xaml ├── App.xaml.cs ├── Images │ ├── WPF_Csharp.png │ ├── bg.jpg │ └── vs.png ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── ParallaxEffectDemo.csproj ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── packages.config ├── README.md └── packages └── DevExpressMvvm.17.1.6.0 ├── DevExpressMvvm.17.1.6.0.nupkg └── lib └── net40-client ├── DevExpress.Mvvm.UI.dll └── DevExpress.Mvvm.dll /Animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiptonDev/ParallaxEffect/24258aceb33ebb09fafd1d440de36eb90a974bd9/Animation.gif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Alexander 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ParallaxEffect.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27130.2027 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParallaxEffect", "ParallaxEffect\ParallaxEffect.csproj", "{1A917F2A-0627-4C17-AEBF-C5B1BACD0EC6}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParallaxEffectDemo", "ParallaxEffectDemo\ParallaxEffectDemo.csproj", "{A5768D16-6766-484D-BA2E-62B9CE88301C}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {1A917F2A-0627-4C17-AEBF-C5B1BACD0EC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {1A917F2A-0627-4C17-AEBF-C5B1BACD0EC6}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {1A917F2A-0627-4C17-AEBF-C5B1BACD0EC6}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {1A917F2A-0627-4C17-AEBF-C5B1BACD0EC6}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {A5768D16-6766-484D-BA2E-62B9CE88301C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A5768D16-6766-484D-BA2E-62B9CE88301C}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A5768D16-6766-484D-BA2E-62B9CE88301C}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {A5768D16-6766-484D-BA2E-62B9CE88301C}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {E2015ABC-1E24-4D98-9328-58D51F9EDBD6} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /ParallaxEffect/Parallax.cs: -------------------------------------------------------------------------------- 1 | using DevExpress.Mvvm.UI.Interactivity; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using System.Windows.Input; 5 | using System.Windows.Media; 6 | 7 | namespace ParallaxEffect 8 | { 9 | public class Parallax : Behavior 10 | { 11 | #region Dependency 12 | public static readonly DependencyProperty UseParallaxProperty = DependencyProperty.RegisterAttached("UseParallax", typeof(bool), typeof(Parallax), new PropertyMetadata(false)); 13 | 14 | public static bool GetUseParallax(DependencyObject obj) => (bool)obj.GetValue(UseParallaxProperty); 15 | public static void SetUseParallax(DependencyObject obj, bool value) => obj.SetValue(UseParallaxProperty, value); 16 | 17 | public static readonly DependencyProperty XOffsetProperty = DependencyProperty.RegisterAttached("XOffset", typeof(int), typeof(Parallax), new PropertyMetadata(0)); 18 | 19 | public static readonly DependencyProperty YOffsetProperty = DependencyProperty.RegisterAttached("YOffset", typeof(int), typeof(Parallax), new PropertyMetadata(0)); 20 | 21 | public static readonly DependencyProperty XDirectionProperty = DependencyProperty.RegisterAttached("XDirection", typeof(ParallaxDirection), typeof(Parallax), new PropertyMetadata(ParallaxDirection.From)); 22 | 23 | public static readonly DependencyProperty YDirectionProperty = DependencyProperty.RegisterAttached("YDirection", typeof(ParallaxDirection), typeof(Parallax), new PropertyMetadata(ParallaxDirection.From)); 24 | 25 | public static int GetXOffset(DependencyObject obj) => (int)obj.GetValue(XOffsetProperty); 26 | public static void SetXOffset(DependencyObject obj, int value) => obj.SetValue(XOffsetProperty, value); 27 | public static int GetYOffset(DependencyObject obj) => (int)obj.GetValue(YOffsetProperty); 28 | public static void SetYOffset(DependencyObject obj, int value) => obj.SetValue(YOffsetProperty, value); 29 | public static ParallaxDirection GetXDirection(DependencyObject obj) => (ParallaxDirection)obj.GetValue(XDirectionProperty); 30 | public static void SetXDirection(DependencyObject obj, ParallaxDirection value) => obj.SetValue(XDirectionProperty, value); 31 | public static ParallaxDirection GetYDirection(DependencyObject obj) => (ParallaxDirection)obj.GetValue(YDirectionProperty); 32 | public static void SetYDirection(DependencyObject obj, ParallaxDirection value) => obj.SetValue(YDirectionProperty, value); 33 | #endregion 34 | 35 | protected override void OnAttached() 36 | { 37 | AssociatedObject.MouseMove += AssociatedObject_MouseMove; 38 | } 39 | 40 | protected override void OnDetaching() 41 | { 42 | AssociatedObject.MouseMove -= AssociatedObject_MouseMove; 43 | } 44 | 45 | private void AssociatedObject_MouseMove(object sender, MouseEventArgs e) 46 | { 47 | if (!(AssociatedObject.Content is Panel content)) 48 | return; 49 | 50 | var mouse = e.GetPosition(AssociatedObject); 51 | 52 | foreach (FrameworkElement item in content.Children) 53 | { 54 | if (!GetUseParallax(item)) 55 | continue; 56 | 57 | int xoffset = GetXOffset(item); 58 | int yoffset = GetYOffset(item); 59 | ParallaxDirection xdirection = GetXDirection(item); 60 | ParallaxDirection ydirection = GetYDirection(item); 61 | 62 | double newX = AssociatedObject.ActualHeight - (xdirection == ParallaxDirection.From ? (mouse.X / xoffset) : -(mouse.X / xoffset)) - AssociatedObject.ActualHeight; 63 | double newY = AssociatedObject.ActualWidth - (xdirection == ParallaxDirection.From ? (mouse.Y / yoffset) : -(mouse.Y / yoffset)) - AssociatedObject.ActualWidth; 64 | 65 | if (!(item.RenderTransform is TranslateTransform)) 66 | item.RenderTransform = new TranslateTransform(newX, newY); 67 | else 68 | { 69 | TranslateTransform transform = (TranslateTransform)item.RenderTransform; 70 | if (xoffset > 0) 71 | transform.X = newX; 72 | if (yoffset > 0) 73 | transform.Y = newY; 74 | } 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ParallaxEffect/ParallaxDirection.cs: -------------------------------------------------------------------------------- 1 | namespace ParallaxEffect 2 | { 3 | /// 4 | /// Направление движения объектов от мыши. 5 | /// 6 | public enum ParallaxDirection 7 | { 8 | /// 9 | /// Смещение объектов ЗА мышкой. 10 | /// Мышь влево - объект влево. 11 | /// 12 | Behind, 13 | 14 | /// 15 | /// Смещение объектов ОТ мышки. 16 | /// Мышь влево - объект вправо. 17 | /// 18 | From 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ParallaxEffect/ParallaxEffect.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1A917F2A-0627-4C17-AEBF-C5B1BACD0EC6} 8 | Library 9 | Properties 10 | ParallaxEffect 11 | ParallaxEffect 12 | v4.6.1 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\DevExpressMvvm.17.1.6.0\lib\net40-client\DevExpress.Mvvm.dll 35 | 36 | 37 | ..\packages\DevExpressMvvm.17.1.6.0\lib\net40-client\DevExpress.Mvvm.UI.dll 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /ParallaxEffect/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Общие сведения об этой сборке предоставляются следующим набором 6 | // набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения, 7 | // связанные со сборкой. 8 | [assembly: AssemblyTitle("ParallaxEffect")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ParallaxEffect")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми 18 | // для компонентов COM. Если необходимо обратиться к типу в этой сборке через 19 | // COM, задайте атрибуту ComVisible значение TRUE для этого типа. 20 | [assembly: ComVisible(false)] 21 | 22 | // Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM 23 | [assembly: Guid("1a917f2a-0627-4c17-aebf-c5b1bacd0ec6")] 24 | 25 | // Сведения о версии сборки состоят из следующих четырех значений: 26 | // 27 | // Основной номер версии 28 | // Дополнительный номер версии 29 | // Номер сборки 30 | // Редакция 31 | // 32 | // Можно задать все значения или принять номер сборки и номер редакции по умолчанию. 33 | // используя "*", как показано ниже: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ParallaxEffect/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ParallaxEffectDemo/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ParallaxEffectDemo/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ParallaxEffectDemo/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace ParallaxEffectDemo 10 | { 11 | /// 12 | /// Логика взаимодействия для App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ParallaxEffectDemo/Images/WPF_Csharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiptonDev/ParallaxEffect/24258aceb33ebb09fafd1d440de36eb90a974bd9/ParallaxEffectDemo/Images/WPF_Csharp.png -------------------------------------------------------------------------------- /ParallaxEffectDemo/Images/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiptonDev/ParallaxEffect/24258aceb33ebb09fafd1d440de36eb90a974bd9/ParallaxEffectDemo/Images/bg.jpg -------------------------------------------------------------------------------- /ParallaxEffectDemo/Images/vs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiptonDev/ParallaxEffect/24258aceb33ebb09fafd1d440de36eb90a974bd9/ParallaxEffectDemo/Images/vs.png -------------------------------------------------------------------------------- /ParallaxEffectDemo/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  10 | 11 | 12 | 13 | 14 | 15 | 16 | 22 | 23 | 31 | 32 | 40 | 41 | 48 | 49 | 50 | 51 |