Skip to content

Commit

Permalink
Fix: DependencyVMProperty when property names differ.
Browse files Browse the repository at this point in the history
  • Loading branch information
GregaMohorko committed Mar 21, 2018
1 parent 039df6f commit b0826de
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 29 deletions.
10 changes: 9 additions & 1 deletion src/GM.WPF/GM.WPF.Test/App.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!--
MIT License
Expand Down Expand Up @@ -30,4 +30,12 @@ Author: Grega Mohorko
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommonServiceLocator" publicKeyToken="489b6accfaf20ef0" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
16 changes: 8 additions & 8 deletions src/GM.WPF/GM.WPF.Test/GM.WPF.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
<Reference Include="CommonServiceLocator, Version=2.0.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll</HintPath>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
Expand All @@ -48,11 +48,11 @@
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
</Reference>
<Reference Include="GM.Utility, Version=1.2.1.0, Culture=neutral, PublicKeyToken=a1ae152199607549, processorArchitecture=MSIL">
<HintPath>..\packages\GM.Utility.1.2.1\lib\netstandard2.0\GM.Utility.dll</HintPath>
<Reference Include="GM.Utility, Version=1.2.5.0, Culture=neutral, PublicKeyToken=a1ae152199607549, processorArchitecture=MSIL">
<HintPath>..\packages\GM.Utility.1.2.5\lib\netstandard2.0\GM.Utility.dll</HintPath>
</Reference>
<Reference Include="PropertyChanged, Version=2.2.6.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.2.2.6\lib\net452\PropertyChanged.dll</HintPath>
<Reference Include="PropertyChanged, Version=2.2.9.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.2.2.9\lib\net452\PropertyChanged.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -131,11 +131,11 @@
<None Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.2.3.25\build\Fody.targets" Condition="Exists('..\packages\Fody.2.3.25\build\Fody.targets')" />
<Import Project="..\packages\Fody.2.4.6\build\Fody.targets" Condition="Exists('..\packages\Fody.2.4.6\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.3.25\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.3.25\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.2.4.6\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.4.6\build\Fody.targets'))" />
</Target>
</Project>
8 changes: 4 additions & 4 deletions src/GM.WPF/GM.WPF.Test/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Created: 2017-11-26
Author: Grega Mohorko
-->
<packages>
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net461" />
<package id="Fody" version="2.3.25" targetFramework="net461" developmentDependency="true" />
<package id="GM.Utility" version="1.2.1" targetFramework="net461" />
<package id="CommonServiceLocator" version="2.0.3" targetFramework="net461" />
<package id="Fody" version="2.4.6" targetFramework="net461" developmentDependency="true" />
<package id="GM.Utility" version="1.2.5" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.4.1" targetFramework="net461" />
<package id="PropertyChanged.Fody" version="2.2.6" targetFramework="net461" developmentDependency="true" />
<package id="PropertyChanged.Fody" version="2.2.9" targetFramework="net461" developmentDependency="true" />
</packages>
27 changes: 26 additions & 1 deletion src/GM.WPF/GM.WPF/Controls/BaseControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ private void DisposeViewModel()
}
}

/// <summary>
/// Creates a dependency property that, when updated, will also update the value of a property in the view model.
/// </summary>
/// <typeparam name="TOwner">The type of the control.</typeparam>
/// <typeparam name="TViewModel">The type of the view model.</typeparam>
/// <param name="name">The name of the dependency property.</param>
/// <param name="viewModelPropertyName">The name of the property in the view model to bind to. If null, it is considered to be the same as the name of the owner property.</param>
protected static DependencyProperty DependencyVMProperty<TOwner, TViewModel>(string name, string viewModelPropertyName = null)
{
return DependencyVMProperty(name, typeof(TOwner), typeof(TViewModel), viewModelPropertyName);
}

/// <summary>
/// Creates a dependency property that, when updated, will also update the value of a property in the view model.
/// </summary>
Expand All @@ -103,6 +115,19 @@ protected static DependencyProperty DependencyVMProperty(string name,Type ownerT
return DependencyVMProperty(name, ownerType, null, viewModelType, viewModelPropertyName);
}

/// <summary>
/// Creates a dependency property that, when updated, will also update the value of a property in the view model.
/// </summary>
/// <typeparam name="TOwner">The type of the control.</typeparam>
/// <typeparam name="TViewModel">The type of the view model.</typeparam>
/// <param name="name">The name of the dependency property.</param>
/// <param name="defaultValue">The default value of this property.</param>
/// <param name="viewModelPropertyName">The name of the property in the view model to bind to. If null, it is considered to be the same as the name of the owner property.</param>
protected static DependencyProperty DependencyVMProperty<TOwner,TViewModel>(string name,object defaultValue,string viewModelPropertyName=null)
{
return DependencyVMProperty(name, typeof(TOwner), defaultValue, typeof(TViewModel), viewModelPropertyName);
}

/// <summary>
/// Creates a dependency property that, when updated, will also update the value of a property in the view model.
/// </summary>
Expand Down Expand Up @@ -137,7 +162,7 @@ void propertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventA
// the new value of the dependency property that was set
var newValue = baseControl.GetPropertyValue(name);
// sets the new value of the property to the property in the view model
vm.SetProperty(name, newValue);
vm.SetProperty(viewModelPropertyName, newValue);
}

if(defaultValue == null) {
Expand Down
22 changes: 14 additions & 8 deletions src/GM.WPF/GM.WPF/GM.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,31 @@
<AssemblyOriginatorKeyFile>GM.StrongNameKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonServiceLocator, Version=2.0.2.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.2\lib\net45\CommonServiceLocator.dll</HintPath>
<Reference Include="CommonServiceLocator, Version=2.0.3.0, Culture=neutral, PublicKeyToken=489b6accfaf20ef0, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.2.0.3\lib\net45\CommonServiceLocator.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.4.1.0, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Extras, Version=5.4.1.0, Culture=neutral, PublicKeyToken=669f0b5e8f868abf, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Extras.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GalaSoft.MvvmLight.Platform, Version=5.4.1.0, Culture=neutral, PublicKeyToken=5f873c45e98af8a1, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.4.1\lib\net45\GalaSoft.MvvmLight.Platform.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GM.Utility, Version=1.2.1.0, Culture=neutral, PublicKeyToken=a1ae152199607549, processorArchitecture=MSIL">
<HintPath>..\packages\GM.Utility.1.2.1\lib\netstandard2.0\GM.Utility.dll</HintPath>
<Reference Include="GM.Utility, Version=1.2.5.0, Culture=neutral, PublicKeyToken=a1ae152199607549, processorArchitecture=MSIL">
<HintPath>..\packages\GM.Utility.1.2.5\lib\netstandard2.0\GM.Utility.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="PropertyChanged, Version=2.2.6.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.2.2.6\lib\net452\PropertyChanged.dll</HintPath>
<Reference Include="PropertyChanged, Version=2.2.9.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.2.2.9\lib\net452\PropertyChanged.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -133,6 +138,7 @@
<Compile Include="Windows\BaseWindow.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="GM.StrongNameKey.snk" />
<None Include="GM.WPF.licenseheader" />
<None Include="packages.config" />
Expand Down Expand Up @@ -183,11 +189,11 @@
<None Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.2.3.25\build\Fody.targets" Condition="Exists('..\packages\Fody.2.3.25\build\Fody.targets')" />
<Import Project="..\packages\Fody.2.4.6\build\Fody.targets" Condition="Exists('..\packages\Fody.2.4.6\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.3.25\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.3.25\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.2.4.6\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.4.6\build\Fody.targets'))" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/GM.WPF/GM.WPF/GM.WPF.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<iconUrl>https://mohorko.info/favicon.ico</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Improved the behavior of TaskDialog.</releaseNotes>
<releaseNotes>Fixed a bug in the DependencyVMProperty when the name of the view models property differs from the controls.</releaseNotes>
<copyright>$copyright$</copyright>
<tags>WPF MVVM controls utility extensions dialogs converters behaviors windows</tags>
</metadata>
Expand Down
4 changes: 2 additions & 2 deletions src/GM.WPF/GM.WPF/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.1")]
[assembly: AssemblyFileVersion("1.0.1.1")]
[assembly: AssemblyVersion("1.0.1.2")]
[assembly: AssemblyFileVersion("1.0.1.2")]
38 changes: 38 additions & 0 deletions src/GM.WPF/GM.WPF/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
MIT License
Copyright (c) 2018 Grega Mohorko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Project: GM.WPF
Created: 2018-3-21
Author: GregaMohorko
-->
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommonServiceLocator" publicKeyToken="489b6accfaf20ef0" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.3.0" newVersion="2.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
8 changes: 4 additions & 4 deletions src/GM.WPF/GM.WPF/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Created: 2017-10-29
Author: Grega Mohorko
-->
<packages>
<package id="CommonServiceLocator" version="2.0.2" targetFramework="net461" />
<package id="Fody" version="2.3.25" targetFramework="net461" developmentDependency="true" />
<package id="GM.Utility" version="1.2.1" targetFramework="net461" />
<package id="CommonServiceLocator" version="2.0.3" targetFramework="net461" />
<package id="Fody" version="2.4.6" targetFramework="net461" developmentDependency="true" />
<package id="GM.Utility" version="1.2.5" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.4.1" targetFramework="net461" />
<package id="PropertyChanged.Fody" version="2.2.6" targetFramework="net461" developmentDependency="true" />
<package id="PropertyChanged.Fody" version="2.2.9" targetFramework="net461" developmentDependency="true" />
</packages>

0 comments on commit b0826de

Please sign in to comment.