AutoCatUwp/AutoCat/Controls/TextCell.xaml.cs

67 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace AutoCat.Controls
{
public sealed partial class TextCell : UserControl
{
#region Dependency properties
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(TextCell), new PropertyMetadata(null, OnTitleChanged));
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Title", typeof(string), typeof(TextCell), new PropertyMetadata(null, OnValueChanged));
#endregion
#region Properties
public string Title
{
get => (string)GetValue(TitleProperty);
set => SetValue(TitleProperty, value);
}
public string Value
{
get => (string)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}
#endregion
public TextCell()
{
this.InitializeComponent();
}
private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if(d is TextCell cell && e.NewValue is string title)
{
cell.TitleBox.Text = title ?? "";
}
}
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is TextCell cell && e.NewValue is string value)
{
cell.ValueBox.Text = value ?? "";
}
}
}
}