From cb4acd590a2d44b37d47bc82c850fbe0b7f65ed1 Mon Sep 17 00:00:00 2001 From: "Andy (Steve) De George" <67293991+adegeo@users.noreply.github.com> Date: Thu, 21 Oct 2021 12:35:11 -0700 Subject: [PATCH] Backport the fix to prop precedence from .NET to Framework (#1171) * Update page4.xaml * Update page4.xaml * Add snippet * Change reference --- .../dependency-property-value-precedence.md | 2 +- .../xaml/App.xaml | 9 ++ .../xaml/App.xaml.cs | 17 +++ .../xaml/AssemblyInfo.cs | 10 ++ .../xaml/CodeSampleCsharp.csproj | 24 ++++ .../xaml/MainWindow.xaml | 34 +++++ .../xaml/MainWindow.xaml.cs | 48 +++++++ .../xaml/Properties/Resources.Designer.cs | 63 +++++++++ .../xaml/Properties/Resources.resx | 120 ++++++++++++++++++ .../PropertiesOvwSupport/CSharp/page4.xaml | 45 ++++--- 10 files changed, 350 insertions(+), 22 deletions(-) create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml.cs create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/AssemblyInfo.cs create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/CodeSampleCsharp.csproj create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml.cs create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.Designer.cs create mode 100644 dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.resx diff --git a/dotnet-desktop-guide/framework/wpf/advanced/dependency-property-value-precedence.md b/dotnet-desktop-guide/framework/wpf/advanced/dependency-property-value-precedence.md index 99090d6..d383be4 100644 --- a/dotnet-desktop-guide/framework/wpf/advanced/dependency-property-value-precedence.md +++ b/dotnet-desktop-guide/framework/wpf/advanced/dependency-property-value-precedence.md @@ -23,7 +23,7 @@ ms.assetid: 1fbada8e-4867-4ed1-8d97-62c07dad7ebc ## Dependency Properties Might Be "Set" in Multiple Places The following is example [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] where the same property () has three different "set" operations that might influence the value. - [!code-xaml[PropertiesOvwSupport#DPPrecedence](~/samples/snippets/csharp/VS_Snippets_Wpf/PropertiesOvwSupport/CSharp/page4.xaml#dpprecedence)] + :::code language="xaml" source="./snippets/dependency-property-value-precedence/xaml/MainWindow.xaml" id="DependencyPropertyValuePrecedence"::: Here, which color do you expect will apply—red, green, or blue? diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml new file mode 100644 index 0000000..867d2f0 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml.cs b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml.cs new file mode 100644 index 0000000..3128552 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace CodeSampleCsharp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/AssemblyInfo.cs b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/CodeSampleCsharp.csproj b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/CodeSampleCsharp.csproj new file mode 100644 index 0000000..8824b2f --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/CodeSampleCsharp.csproj @@ -0,0 +1,24 @@ + + + + WinExe + net5.0-windows + true + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml new file mode 100644 index 0000000..b36725c --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml.cs b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml.cs new file mode 100644 index 0000000..1c3615d --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/MainWindow.xaml.cs @@ -0,0 +1,48 @@ +using System.Windows; +using System.Windows.Controls; + +namespace CodeSampleCsharp +{ + /// + /// Interaction logic for MainWindow.xaml. + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + + // + Button myButton = new(); + myButton.Width = 200.0; + // + + // + double whatWidth = myButton.Width; + // + } + + // + public static readonly DependencyProperty IsSpinningProperty = DependencyProperty.Register( + "IsSpinning", typeof(bool), + typeof(MainWindow) + ); + + public bool IsSpinning + { + get => (bool)GetValue(IsSpinningProperty); + set => SetValue(IsSpinningProperty, value); + } + // + } + + // + public class SpinnerControl : ItemsControl + { + static SpinnerControl() => DefaultStyleKeyProperty.OverrideMetadata( + typeof(SpinnerControl), + new FrameworkPropertyMetadata(typeof(SpinnerControl)) + ); + } + // +} diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.Designer.cs b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.Designer.cs new file mode 100644 index 0000000..64552f9 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CodeSampleCsharp.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CodeSampleCsharp.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.resx b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/dotnet-desktop-guide/framework/wpf/advanced/snippets/dependency-property-value-precedence/xaml/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PropertiesOvwSupport/CSharp/page4.xaml b/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PropertiesOvwSupport/CSharp/page4.xaml index 8e3dc2e..75e7eee 100644 --- a/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PropertiesOvwSupport/CSharp/page4.xaml +++ b/dotnet-desktop-guide/samples/snippets/csharp/VS_Snippets_Wpf/PropertiesOvwSupport/CSharp/page4.xaml @@ -4,27 +4,30 @@ x:Class="MyNamespace.MyCode" Loaded="BAQ" > - - - - Hello - - - - + + + + + + + + + + + -