+ styleName = control.GetStyleName();
+
+ if( styleName.empty() )
+ {
+ styleName = control.GetTypeName();
+ }
+
+ // Apply the style after choosing the correct actual style (e.g. landscape or portrait)
+ std::vector<std::string> qualifiers;
+ CollectQualifiers( qualifiers );
+
+ bool found = 0;
+ std::string qualifiedStyleName;
+ do
+ {
+ qualifiedStyleName.clear();
+ BuildQualifiedStyleName( styleName, qualifiers, qualifiedStyleName );
+
+ // Break if style found or we have tried the root style name (qualifiers is empty)
+ if( GetImpl(builder).LookupStyleName( qualifiedStyleName ) )
+ {
+ found = true;
+ break;
+ }
+ if( qualifiers.size() == 0 )
+ {
+ break;
+ }
+ // Remove the last qualifier in an attempt to find a style that is valid
+ qualifiers.pop_back();
+ } while (!found);
+
+ if(found)
+ {
+ styleName = qualifiedStyleName;
+ }
+ return found;