New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stylesheets #1207
Stylesheets #1207
Conversation
b8e5e98
to
ec2c0ca
Compare
1b1f6ce
to
eb4e837
Compare
.nuspec/Xamarin.Forms.targets
Outdated
</CoreCompileDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="CssG"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the new CssG task is responsible for creating XamlResourceIdAttributes for Css file
|
||
[assembly: StyleProperty("color", typeof(ITextElement), nameof(TextElement.TextColorProperty))] | ||
[assembly: StyleProperty("background-color", typeof(VisualElement), nameof(VisualElement.BackgroundColorProperty))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the mapping table to be completed, matching css property names to XF properties
propertyChanged: (bp, o, n) => ((VisualElement)bp).OnStyleSheetChanged((StyleSheet)o, (StyleSheet)n)); | ||
|
||
[TypeConverter(typeof(StyleSheetConverter))] | ||
public StyleSheet StyleSheet { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no actual public way to create a StyleSheet, so this expects a string uri in Xaml and the StyleSheet will be generated
10ae2cb
to
34d89b2
Compare
[assembly: StyleProperty("border-width", typeof(Button), nameof(Button.BorderWidth))] | ||
[assembly: StyleProperty("color", typeof(ITextElement), nameof(TextElement.TextColorProperty))] | ||
//[assembly:StyleProperty("direction", .., ..)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samhouts your help is needed here
12b249f
to
5b5a6bf
Compare
8d38989
to
45cd0a5
Compare
914a135
to
2130009
Compare
.nuspec/Xamarin.Forms.targets
Outdated
</CoreCompileDependsOn> | ||
</PropertyGroup> | ||
|
||
<Target Name="CssG"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change it to BeforeTarget="BeforeCompile"
and remove the property group
[TestCase("page>stacklayout>contentview>label", false, false, true, false, false, false)] | ||
[TestCase("visualelement", false, false, false, false, false, false)] | ||
[TestCase("^visualelement", true, true, true, true, true, true)] | ||
[TestCase("^layout", false, false, false, false, false, true)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is how me make CSS support language with inheritance
@@ -1156,6 +1156,9 @@ static bool CanAddToResourceDictionary(TypeReference collectionType, IElementNod | |||
if (node.XmlType.Name == "ResourceDictionary") | |||
return true; | |||
|
|||
if (node.XmlType.Name == "StyleSheet") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace those 3 checks by a single reflection based one (see AddToRD below)
cb35e96
to
dc9c48e
Compare
* 'master' of https://github.com/xamarin/Xamarin.Forms: (53 commits) Add implicit color conversion to .NET Standard's System.Drawing.Color (xamarin#1359) [WPF, GTK, TIZEN] Replace obsolete OutlineColor by BorderColor (xamarin#1443) Stylesheets (xamarin#1207) [WPF] Add Deserializer implementation (xamarin#1411) [Build]Update provisioning submodule [Build] Update provisioning [UWP] Optimized ZIndexing for a thirty-nine percent speed boot on loa… (xamarin#1196) [Xaml] execute XamlG and XamlC on UWP SAP (xamarin#1391) [iOS] Update status bar color while page is appearing (xamarin#1288) Add condition SdkInt >= JellyBeanMr1 for set flow direction (xamarin#1388) Use GlobalAssemblyInfo on tizen backend (xamarin#1397) [Build] Bump to 15.5.2 revert part of xamarin#1370. keep the test project out of netstandard for now (xamarin#1402) fix typo in csproj Fix for netstandard projects (xamarin#1382) [Xaml] open the api for loading xaml from string (xamarin#1394) [Android] Prevent a custom Entry/Editor Drawable from modifying non-custom ones (xamarin#1197) [build] force build on vs2015 Add Xamarin.Forms.ControlGallery.Tizen project (xamarin#1389) Move XF.Build.Tasks to nestandard2.0 (xamarin#1370) ...
{ | ||
public static readonly BindableProperty OutlineColorProperty = BindableProperty.Create("OutlineColor", typeof(Color), typeof(Frame), Color.Default); | ||
[Obsolete("OutlineColorProperty is obsolete as of version 3.0.0. Please use BorderColorProperty instead.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change caused #1566
I am not sure if someone already asked about this before but if someone did, please guide me to the answer. How to add different CSS for tablets like the iPad or android tablets in general? so, I had to do many steps to solve this issue such as:
`if (Device.Idiom == TargetIdiom.Phone)
As you can see it's a lot of variables and conditions to set for every page. Is this issue still there or does CSS provide a solution to that? UPDATE: NeverMind that long post
|
Can styles on an element be changed at runtime? They are applied as expected on initial load but I seem unable to dynamically change them at runtime based on some event. For example, in a page code-behind this scenario:
This has no effect, and does not update |
@mmacneil please open an issue, we will discuss that over there |
Done: 2678 Thanks Stephane |
Will width work in percentage. |
* try to do a type of to see if this fixes it * Update TextToSpeech.ios.tvos.watchos.cs * Update TextToSpeech.ios.tvos.watchos.cs * Fix formatting
Description of Change
Support cascading StyleSheets.
Support all selector (no media selectors)
Preliminary note
This code and feature is brand new. The API shouldn't change much, but some of the behaviors might be slightly altered in the future, depending on the feedback received.
Supported Selectors
.class
.header
StyleClass
property containing 'header'#id
#email
StyleId
set toemail
. IfStyleId
is not set, fallback tox:Name
. When using Xaml, always preferx:Name
overStyleId
.*
*
element
label
^base
^contentpage
ContentPage
as base class, including ContentPage itself. Case irrelevant. This selector isn't present in the CSS specification, and only applies to XF.element,element
label,button
element element
stacklayout label
element>element
stacklayout>label
element+element
label+entry
element~element
label~entry
Unsupported Selectors (for this version)
[attribute]
selectors@media
or@supports
selectors:
or::
selectorsSelector combinations
Selectors can be combined without limitation, like in
StackLayout > ContentView > label.email
. But keep it sane !Precedence
Styles with matching selectors are all applied, one by one, in definition order. Styles defined on the item itself is always applied last.
This is the expected behavior in most cases, even if doesn't 100% match common CSS implementations.
Specificity, and specificity overrides (
!important
) are not supported. This is a known issue.Supported properties
grayed
, while types are italic)background-color
VisualElement
initial
background-color: springgreen;
background-image
Page
initial
background-image: bg.png;
border-color
Button
,Frame
initial
border-color: #9acd32;
border-width
Button
initial
border-width: .5;
color
Button
,DatePicker
,Editor
,Entry
,Label
,Picker
,SearchBar
,TimePicker
initial
color: rgba(255, 0, 0, 0.3);
direction
VisualElement
ltr
|rtl
|inherit
,initial
direction: rtl;
font-family
Button
,DatePicker
,Editor
,Entry
,Label
,Picker
,SearchBar
,TimePicker
,Span
initial
font-family: Consolas;
font-size
Button
,DatePicker
,Editor
,Entry
,Label
,Picker
,SearchBar
,TimePicker
,Span
initial
font-size: 12;
font-style
Button
,DatePicker
,Editor
,Entry
,Label
,Picker
,SearchBar
,TimePicker
,Span
bold
|italic
|initial
font-style: bold;
height
VisualElement
initial
margin
View
initial
margin: 6 12;
margin-left
View
initial
margin-left: 3;
margin-top
View
initial
margin-top: 2;
margin-right
View
initial
margin-right: 1;
margin-bottom
View
initial
margin-bottom: 6;
min-height
VisualElement
initial
min-width
VisualElement
initial
opacity
VisualElement
initial
opacity: .3;
padding
Layout
,Page
initial
padding: 6 12 12;
padding-left
Layout
,Page
initial
padding-left: 3;
padding-top
Layout
,Page
initial
padding-top: 4;
padding-right
Layout
,Page
initial
padding-right: 2;
padding-bottom
Layout
,Page
initial
padding-bottom: 6;
text-align
Entry
,EntryCell
,Label
,SearchBar
left
|right
|center
|start
|end
|initial
. It is recommended to avoidleft
andright
in non-ltr environmentstext-align: right;
visibility
VisualElement
true
|visible
|false
|hidden
|collapse
|initial
visibility: hidden;
width
VisualElement
initial
Unsupported Common Properties
all: initial
,font
,border
Colors
X11
color (https://en.wikipedia.org/wiki/X11_color_names), which happens to match CSS Colors, UWP predefined colors and XF Colors. Case insensitive#rgb
,#argb
,#rrggbb
,#aarrggbb
rgb(255,0,0)
,rgb(100%,0%,0%)
=> values in range 0-255 or 0%-100%rgba(255, 0, 0, 0.8)
,rgba(100%, 0%, 0%, 0.8)
=> opacity is 0.0-1.0hsl(120, 100%, 50%)
=> h is 0-360, s and l are 0%-100%hsla(120, 100%, 50%, .8)
=> opacity is 0.0-1.0Thickness
One, two, three or four values, separated by white spaces.
NamedSize
One of the following value, case insensitive. Exact meaning depends of the platform and the control
default
,micro
,small
,medium
,large
Initial
initial
is a valid value for all properties. It clears the value (resets to default) that was set from another Style.Additional remarks
inherit
value and that you can't set the font-size to a layout, and expect all the labels in that layout to inherit the value. The only exception is thedirection
property, which supportsinherit
, and that's the default value.Usage
XAML (preferred)
the
Source
argument takes an Uri relative to the current xaml control, or relative to the application root if it starts with a/
. Thestyle.css
has to be an EmbeddedResource.alternatively, you can inline your style in a
CDATA
Sectiondo not abuse of that second syntax.
in C#
From an embedded resource:
or from a
TextReader
:StyleSheet, XamlC and other potential optimizations
At this time, CSS StyleSheets are parsed and evaluated at runtime. That aren't compiled. Every time a StyleSheet is used, it's reparsed again. If parsing time is an issue, enabling caching is trivial, but comes at memory cost.
Bugs Fixed
None. but It'll introduce some new ones
API Changes
Added
Not that much new API...
Obsoleted
Behavioral Changes
/
PR Checklist