@@ -5,6 +5,9 @@ import {ContentView} from 'ui/content-view';
55import { LayoutBase } from 'ui/layouts/layout-base' ;
66import { ViewClass , getViewClass , getViewMeta , isKnownView , ViewExtensions , NgView , ViewClassMeta } from './element-registry' ;
77import { getSpecialPropertySetter } from "ui/builder/special-properties" ;
8+ import * as styleProperty from "ui/styling/style-property" ;
9+ import { StyleProperty , getPropertyByName , withStyleProperty } from "ui/styling/style-property" ;
10+ import { ValueSource } from "ui/core/dependency-observable" ;
811import { ActionBar , ActionItem , NavigationButton } from "ui/action-bar" ;
912import trace = require( "trace" ) ;
1013import { device , platformNames , Device } from "platform" ;
@@ -287,7 +290,38 @@ export class ViewUtil {
287290 view . cssClass = classValue ;
288291 }
289292
293+ private resolveCssValue ( styleValue : string ) : string {
294+ return styleValue ;
295+ }
296+ 297+ private setStyleValue ( view : NgView , property : StyleProperty , value : any ) {
298+ try {
299+ view . style . _setValue ( property , value , ValueSource . Local ) ;
300+ } catch ( ex ) {
301+ trace . write ( "Error setting property: " + property . name + " view: " + view + " value: " + value + " " + ex , trace . categories . Style , trace . messageType . error ) ;
302+ }
303+ }
304+ 290305 public setStyleProperty ( view : NgView , styleName : string , styleValue : string ) : void {
291- throw new Error ( "Not implemented: setStyleProperty" ) ;
306+ traceLog ( "setStyleProperty: " + styleName + " = " + styleValue ) ;
307+ 308+ let name = styleName ;
309+ let resolvedValue = this . resolveCssValue ( styleValue ) ;
310+ withStyleProperty ( name , resolvedValue , ( property , value ) => {
311+ if ( isString ( property ) ) {
312+ //Fall back to resolving property by name.
313+ const propertyName = < string > property ;
314+ const resolvedProperty = getPropertyByName ( name ) ;
315+ if ( resolvedProperty ) {
316+ this . setStyleValue ( view , resolvedProperty , resolvedValue ) ;
317+ } else {
318+ traceLog ( "Unknown style property: " + styleName ) ;
319+ }
320+ } else {
321+ const resolvedProperty = < StyleProperty > property ;
322+ this . setStyleValue ( view , resolvedProperty , resolvedValue ) ;
323+ }
324+ 325+ } ) ;
292326 }
293327}
0 commit comments