[C] ITextElement and TextElement (#789)
This commit is contained in:
Родитель
bc53ebe2bf
Коммит
8bc7ba3faa
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Platform;
|
||||
|
@ -8,7 +7,7 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_ButtonRenderer))]
|
||||
public class Button : View, IFontElement, IButtonController, IElementConfiguration<Button>
|
||||
public class Button : View, IFontElement, ITextElement, IButtonController, IElementConfiguration<Button>
|
||||
{
|
||||
public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(Button), null, propertyChanged: (bo, o, n) => ((Button)bo).OnCommandChanged());
|
||||
|
||||
|
@ -21,7 +20,7 @@ namespace Xamarin.Forms
|
|||
public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Button), null,
|
||||
propertyChanged: (bindable, oldVal, newVal) => ((Button)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged));
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Button), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
public static readonly BindableProperty FontProperty = FontElement.FontProperty;
|
||||
|
||||
|
@ -101,8 +100,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
bool IsEnabledCore
|
||||
|
@ -237,6 +236,10 @@ namespace Xamarin.Forms
|
|||
oldvalue.SourceChanged -= OnSourceChanged;
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
|
||||
[DebuggerDisplay("Image Position = {Position}, Spacing = {Spacing}")]
|
||||
[TypeConverter(typeof(ButtonContentTypeConverter))]
|
||||
public sealed class ButtonContentLayout
|
||||
|
@ -304,4 +307,4 @@ namespace Xamarin.Forms
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_DatePickerRenderer))]
|
||||
public class DatePicker : View, IElementConfiguration<DatePicker>
|
||||
public class DatePicker : View, ITextElement,IElementConfiguration<DatePicker>
|
||||
{
|
||||
public static readonly BindableProperty FormatProperty = BindableProperty.Create(nameof(Format), typeof(string), typeof(DatePicker), "d");
|
||||
|
||||
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms
|
|||
public static readonly BindableProperty MaximumDateProperty = BindableProperty.Create(nameof(MaximumDate), typeof(DateTime), typeof(DatePicker), new DateTime(2100, 12, 31),
|
||||
validateValue: ValidateMaximumDate, coerceValue: CoerceMaximumDate);
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(DatePicker), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
readonly Lazy<PlatformConfigurationRegistry<DatePicker>> _platformConfigurationRegistry;
|
||||
|
||||
|
@ -52,8 +52,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
public event EventHandler<DateChangedEventArgs> DateSelected;
|
||||
|
@ -115,5 +115,9 @@ namespace Xamarin.Forms
|
|||
{
|
||||
return _platformConfigurationRegistry.Value.On<T>();
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_EditorRenderer))]
|
||||
public class Editor : InputView, IEditorController, IFontElement, IElementConfiguration<Editor>
|
||||
public class Editor : InputView, IEditorController, IFontElement, ITextElement, IElementConfiguration<Editor>
|
||||
{
|
||||
public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Editor), null, BindingMode.TwoWay, propertyChanged: (bindable, oldValue, newValue) =>
|
||||
{
|
||||
|
@ -19,7 +19,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public static readonly BindableProperty FontAttributesProperty = FontElement.FontAttributesProperty;
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Editor), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
readonly Lazy<PlatformConfigurationRegistry<Editor>> _platformConfigurationRegistry;
|
||||
|
||||
public string Text
|
||||
|
@ -30,8 +31,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
public FontAttributes FontAttributes
|
||||
|
@ -92,5 +93,9 @@ namespace Xamarin.Forms
|
|||
if (handler != null)
|
||||
handler(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_EntryRenderer))]
|
||||
public class Entry : InputView, IFontElement, IEntryController, IElementConfiguration<Entry>
|
||||
public class Entry : InputView, IFontElement, ITextElement, IEntryController, IElementConfiguration<Entry>
|
||||
{
|
||||
public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create("Placeholder", typeof(string), typeof(Entry), default(string));
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace Xamarin.Forms
|
|||
|
||||
public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Entry), null, BindingMode.TwoWay, propertyChanged: OnTextChanged);
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Entry), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
public static readonly BindableProperty HorizontalTextAlignmentProperty = BindableProperty.Create("HorizontalTextAlignment", typeof(TextAlignment), typeof(Entry), TextAlignment.Start);
|
||||
|
||||
|
@ -63,8 +63,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
public FontAttributes FontAttributes
|
||||
|
@ -125,5 +125,9 @@ namespace Xamarin.Forms
|
|||
{
|
||||
return _platformConfigurationRegistry.Value.On<T>();
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
|
||||
namespace Xamarin.Forms
|
||||
{
|
||||
interface ITextElement
|
||||
{
|
||||
//note to implementor: implement the properties publicly
|
||||
Color TextColor { get; }
|
||||
|
||||
//note to implementor: but implement the methods explicitly
|
||||
void OnTextColorPropertyChanged(Color oldValue, Color newValue);
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace Xamarin.Forms
|
|||
{
|
||||
[ContentProperty("Text")]
|
||||
[RenderWith(typeof(_LabelRenderer))]
|
||||
public class Label : View, IFontElement, IElementConfiguration<Label>
|
||||
public class Label : View, IFontElement, ITextElement, IElementConfiguration<Label>
|
||||
{
|
||||
public static readonly BindableProperty HorizontalTextAlignmentProperty = BindableProperty.Create("HorizontalTextAlignment", typeof(TextAlignment), typeof(Label), TextAlignment.Start,
|
||||
propertyChanged: OnHorizontalTextAlignmentPropertyChanged);
|
||||
|
@ -21,7 +21,7 @@ namespace Xamarin.Forms
|
|||
[Obsolete("YAlignProperty is obsolete. Please use VerticalTextAlignmentProperty instead.")]
|
||||
public static readonly BindableProperty YAlignProperty = VerticalTextAlignmentProperty;
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Label), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
public static readonly BindableProperty FontProperty = FontElement.FontProperty;
|
||||
|
||||
|
@ -90,8 +90,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
public TextAlignment VerticalTextAlignment
|
||||
|
@ -186,5 +186,9 @@ namespace Xamarin.Forms
|
|||
{
|
||||
return _platformConfigurationRegistry.Value.On<T>();
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,10 +10,9 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_PickerRenderer))]
|
||||
public class Picker : View, IElementConfiguration<Picker>
|
||||
public class Picker : View, ITextElement, IElementConfiguration<Picker>
|
||||
{
|
||||
public static readonly BindableProperty TextColorProperty =
|
||||
BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(Picker), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
public static readonly BindableProperty TitleProperty =
|
||||
BindableProperty.Create(nameof(Title), typeof(string), typeof(Picker), default(string));
|
||||
|
@ -59,8 +58,8 @@ namespace Xamarin.Forms
|
|||
}
|
||||
|
||||
public Color TextColor {
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
public string Title {
|
||||
|
@ -220,6 +219,10 @@ namespace Xamarin.Forms
|
|||
return _platformConfigurationRegistry.Value.On<T>();
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
|
||||
internal class LockableObservableListWrapper : IList<string>, ICollection<string>, INotifyCollectionChanged, INotifyPropertyChanged, IReadOnlyList<string>, IReadOnlyCollection<string>, IEnumerable<string>, IEnumerable
|
||||
{
|
||||
internal readonly ObservableCollection<string> _list = new ObservableCollection<string>();
|
||||
|
|
|
@ -5,7 +5,7 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_SearchBarRenderer))]
|
||||
public class SearchBar : View, IFontElement, ISearchBarController, IElementConfiguration<SearchBar>
|
||||
public class SearchBar : View, IFontElement, ITextElement, ISearchBarController, IElementConfiguration<SearchBar>
|
||||
{
|
||||
public static readonly BindableProperty SearchCommandProperty = BindableProperty.Create("SearchCommand", typeof(ICommand), typeof(SearchBar), null, propertyChanged: OnCommandChanged);
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace Xamarin.Forms
|
|||
|
||||
public static readonly BindableProperty HorizontalTextAlignmentProperty = BindableProperty.Create("HorizontalTextAlignment", typeof(TextAlignment), typeof(SearchBar), TextAlignment.Start);
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(SearchBar), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
public static readonly BindableProperty PlaceholderColorProperty = BindableProperty.Create("PlaceholderColor", typeof(Color), typeof(SearchBar), Color.Default);
|
||||
|
||||
|
@ -82,8 +82,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
bool IsEnabledCore
|
||||
|
@ -182,5 +182,9 @@ namespace Xamarin.Forms
|
|||
{
|
||||
return _platformConfigurationRegistry.Value.On<T>();
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
static class TextElement
|
||||
{
|
||||
public static readonly BindableProperty TextColorProperty =
|
||||
BindableProperty.Create("TextColor", typeof(Color), typeof(Button), Color.Default,
|
||||
propertyChanged: OnTextColorPropertyChanged);
|
||||
|
||||
static void OnTextColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
((ITextElement)bindable).OnTextColorPropertyChanged((Color)oldValue, (Color)newValue);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,11 +4,11 @@ using Xamarin.Forms.Platform;
|
|||
namespace Xamarin.Forms
|
||||
{
|
||||
[RenderWith(typeof(_TimePickerRenderer))]
|
||||
public class TimePicker : View, IElementConfiguration<TimePicker>
|
||||
public class TimePicker : View, ITextElement, IElementConfiguration<TimePicker>
|
||||
{
|
||||
public static readonly BindableProperty FormatProperty = BindableProperty.Create(nameof(Format), typeof(string), typeof(TimePicker), "t");
|
||||
|
||||
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TimePicker), Color.Default);
|
||||
public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty;
|
||||
|
||||
public static readonly BindableProperty TimeProperty = BindableProperty.Create(nameof(Time), typeof(TimeSpan), typeof(TimePicker), new TimeSpan(0), BindingMode.TwoWay, (bindable, value) =>
|
||||
{
|
||||
|
@ -31,8 +31,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public Color TextColor
|
||||
{
|
||||
get { return (Color)GetValue(TextColorProperty); }
|
||||
set { SetValue(TextColorProperty, value); }
|
||||
get { return (Color)GetValue(TextElement.TextColorProperty); }
|
||||
set { SetValue(TextElement.TextColorProperty, value); }
|
||||
}
|
||||
|
||||
public TimeSpan Time
|
||||
|
@ -45,5 +45,9 @@ namespace Xamarin.Forms
|
|||
{
|
||||
return _platformConfigurationRegistry.Value.On<T>();
|
||||
}
|
||||
|
||||
void ITextElement.OnTextColorPropertyChanged(Color oldValue, Color newValue)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -450,6 +450,8 @@
|
|||
<Compile Include="PlatformConfiguration\macOSSpecific\TabbedPage.cs" />
|
||||
<Compile Include="PlatformConfiguration\macOSSpecific\TabsStyle.cs" />
|
||||
<Compile Include="FontElement.cs" />
|
||||
<Compile Include="ITextElement.cs" />
|
||||
<Compile Include="TextElement.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
@ -467,4 +469,4 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="PlatformConfiguration\macOSSpecific\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace Xamarin.Forms.Platform.WinPhone
|
|||
self.FontWeight = FontWeights.Normal;
|
||||
}
|
||||
|
||||
public static void ApplyFont(this TextElement self, Font font)
|
||||
public static void ApplyFont(this System.Windows.Documents.TextElement self, Font font)
|
||||
{
|
||||
if (font.UseNamedSize)
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Xamarin.Forms.Platform.WinRT
|
|||
self.FontWeight = font.FontAttributes.HasFlag(FontAttributes.Bold) ? FontWeights.Bold : FontWeights.Normal;
|
||||
}
|
||||
|
||||
public static void ApplyFont(this TextElement self, Font font)
|
||||
public static void ApplyFont(this Windows.UI.Xaml.Documents.TextElement self, Font font)
|
||||
{
|
||||
self.FontSize = font.UseNamedSize ? font.NamedSize.GetFontSize() : font.FontSize;
|
||||
self.FontFamily = !string.IsNullOrEmpty(font.FontFamily) ? new FontFamily(font.FontFamily) : (FontFamily)WApplication.Current.Resources["ContentControlThemeFontFamily"];
|
||||
|
|
Загрузка…
Ссылка в новой задаче