@@ -5,6 +5,9 @@ import {ContentView} from 'ui/content-view';
5
5
import { LayoutBase } from 'ui/layouts/layout-base' ;
6
6
import { ViewClass , getViewClass , getViewMeta , isKnownView , ViewExtensions , NgView , ViewClassMeta } from './element-registry' ;
7
7
import { 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" ;
8
11
import { ActionBar , ActionItem , NavigationButton } from "ui/action-bar" ;
9
12
import trace = require( "trace" ) ;
10
13
import { device , platformNames , Device } from "platform" ;
@@ -287,7 +290,38 @@ export class ViewUtil {
287
290
view . cssClass = classValue ;
288
291
}
289
292
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
+
290
305
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
+ } ) ;
292
326
}
293
327
}
0 commit comments