forked from CommunityToolkit/WindowsCommunityToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridExtensions.Layouts.cs
More file actions
48 lines (42 loc) · 2.2 KB
/
GridExtensions.Layouts.cs
File metadata and controls
48 lines (42 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Microsoft.Toolkit.Uwp.UI
{
using LayoutDictionary = System.Collections.Generic.IDictionary<string, Microsoft.Toolkit.Uwp.UI.GridLayoutDefinition>;
/// <summary>
/// Provides Layouts attached property for <see cref="Grid"/> element.
/// </summary>
public static partial class GridExtensions
{
/// <summary>
/// Attached <see cref="DependencyProperty"/> for binding <see cref="LayoutsProperty"/> to a <see cref="Grid"/>
/// </summary>
public static readonly DependencyProperty LayoutsProperty =
DependencyProperty.RegisterAttached("Layouts", typeof(LayoutDictionary), typeof(GridExtensions), new PropertyMetadata(null));
/// <summary>
/// Gets the <see cref="LayoutsProperty"/> associated with the specified <see cref="Grid"/>
/// </summary>
/// <param name="obj">The <see cref="Grid"/> from which to get the associated <see cref="LayoutsProperty"/> value</param>
/// <returns>The <see cref="LayoutsProperty"/> value associated with the <see cref="Grid"/> or null</returns>
public static LayoutDictionary GetLayouts(Grid obj)
{
var dictionary = (LayoutDictionary)obj.GetValue(LayoutsProperty);
if (dictionary is null)
{
dictionary = new Dictionary<string, GridLayoutDefinition>();
SetLayouts(obj, dictionary);
}
return dictionary;
}
/// <summary>
/// Sets the <see cref="LayoutsProperty"/> associated with the specified <see cref="Grid"/>
/// </summary>
/// <param name="obj">The <see cref="Grid"/> to associated the <see cref="LayoutsProperty"/> to</param>
/// <param name="value">The <see cref="LayoutsProperty"/> to bind to the <see cref="Grid"/></param>
public static void SetLayouts(Grid obj, LayoutDictionary value) => obj.SetValue(LayoutsProperty, value);
}
}