Open Montago opened 2 years ago
The challenge with a feature like this is that there can be any combination of inline elements in the content. For example, how would you convert the following to an attribute?
<TextBlock>
<Run FontSize="24" Foreground="#FFFC5185">Title Text</Run><LineBreak/>
<Run>Lorem ipsum</Run>
</TextBlock>
in the case you mention i would leave the elements.
its only text content that should be inserted into attribute
Is there really enough value to do this for only TextBlock
and Label
?
I'm not sure how this could be implemented without shipping with a list of known elements and the attribute/property names that can be used when refactoring.
For example, <Button>click me</Button>
would "collapse" to <Button Content="click me" />
.
There is also a need to consider whether whitespace should be preserved when replacing an element with content that technically only contains text but also has whitespace (including newlines) around the text.
this feature request is largely a "nice to have" to remove all the manual work in organizing the XAML (which is the point of the extension)
I would say that Content.Trim() would be the correct value to insert in the attribute field.
And yes : buttons would also make sense in this case., Maybe have a list of elementnames where this rule applies ?
Additionally, a threshold of when to convert could be made, eg: dont convert content when content length is above N letters (default 100 ?)
Ha. Just seen that Blend does this to XAML that you drag in the designer 🤣
I'm still, not advocating for it though.
It would be nice to have the option to have XAML Styler to convert usual Text content into Attributes, especially for TextBlock, TextBox and Label :
into
And
into