Dynamic objects in Silverlight
I need to request a service for data. After the request I'll use that data to draw a few shapes representing the data.
My question is if it's a preferred way to draw like a library of assets in XAML first, and then use code to copy and place these pre-defined assets around based on the imported data? Or if it's cleaner to go a "code-only" approach and also create the XAML objects using code after reading the dat开发者_Python百科a?
The object are quite simple and we're not depending on a separate designer to create the XAML. I guess that otherwise could be a reason for pre-define the XAML object.
There are many possible ways you could takle this.
I would say the best practice approach would be to have XAML shape definitions that are stored in your project assets. Then you can use Blend to design/modify these shapes. This separates the definition of the shapes from the project code that creates instances of them. Making it easy to change the shapes in the future. Also allows a non-programmer to access and modify them in Blend in the future.
XAML is a declarative language ,meaning XAML is like a code .Therefore its best to use XAML declarations and binding only the data. It will give good performance.
精彩评论