Best-practice to design a view that bases heavily on data in Blend
Posted: 08 Feb 2023, 15:14
Hey everyone,
currently, I am prototyping a UserControl that utilizes a TreeView to display nested ObservableCollections. To build the individual elements of my HierarchicalDataTemplate I need to have SampleData available: on one hand, at design-time to bind the UI elements to the DataModel and to see something on the screen, on the other hand at run-time to be able to click through the menu to check its functionality. Because we integrate Noesis in a C++ project, there is a second level of "run-time" that needs to be kept in mind (Blend/C# and Game/C++).
I would like to know how I can provide the same set of SampleData in all three worlds.
I've already tried different solutions and none is actually practicable. Especially because the task of designing the View will not be done by a programmer in the future.
The closest solutions were...
a) Creating the SampleData and with it the DataModel as a XML file. And importing that file as SampleData in the Data Tab of Blend. This enables me to bind my elements correctly and I can see the results immediately at design-time. But when running the project in Blend, this SampleData does not exist, of course. Therefore, in c# I had to implement the necessary DataType classes, with it the actual ViewModel, and had to populate the ViewModel with my SampleData by hand to create the run-time DataContext. And whenever there is a change in the SampleData, I had to sync it with the c# version.
Finally, after we were satisfied with the draft, we had to translate the C# ViewModel to C++ as well. From now on, we will have to keep all three versions in sync.
Even though this pipeline works technically, I have to repeat myself several times.
b) Using the same SampleData XML file as before but loading it into the XAML via the XmlDataProvider as a Resource. This time, the Data is available in Blend at design-time as well as at run-time, and I can bind my elements to it. This allows quick design iteration cycles without much thought about the data or the model itself. And when we are satisfied, I would only need to extrude the ViewModel once into C++. The big issue here is that I bind my data statically to this XML file and not to some SampleData, meaning XAML expects that this XML file is actually part of the final program. Because of that, the syntax is different: binding to XPATH instead of PATH. And therefore we would have to keep two versions of the XAML file... one for Blend and one for the game. Keeping them in sync is also not very promising.
I hope anyone has some experience and can point me in the right direction.
currently, I am prototyping a UserControl that utilizes a TreeView to display nested ObservableCollections. To build the individual elements of my HierarchicalDataTemplate I need to have SampleData available: on one hand, at design-time to bind the UI elements to the DataModel and to see something on the screen, on the other hand at run-time to be able to click through the menu to check its functionality. Because we integrate Noesis in a C++ project, there is a second level of "run-time" that needs to be kept in mind (Blend/C# and Game/C++).
I would like to know how I can provide the same set of SampleData in all three worlds.
I've already tried different solutions and none is actually practicable. Especially because the task of designing the View will not be done by a programmer in the future.
The closest solutions were...
a) Creating the SampleData and with it the DataModel as a XML file. And importing that file as SampleData in the Data Tab of Blend. This enables me to bind my elements correctly and I can see the results immediately at design-time. But when running the project in Blend, this SampleData does not exist, of course. Therefore, in c# I had to implement the necessary DataType classes, with it the actual ViewModel, and had to populate the ViewModel with my SampleData by hand to create the run-time DataContext. And whenever there is a change in the SampleData, I had to sync it with the c# version.
Finally, after we were satisfied with the draft, we had to translate the C# ViewModel to C++ as well. From now on, we will have to keep all three versions in sync.
Even though this pipeline works technically, I have to repeat myself several times.
b) Using the same SampleData XML file as before but loading it into the XAML via the XmlDataProvider as a Resource. This time, the Data is available in Blend at design-time as well as at run-time, and I can bind my elements to it. This allows quick design iteration cycles without much thought about the data or the model itself. And when we are satisfied, I would only need to extrude the ViewModel once into C++. The big issue here is that I bind my data statically to this XML file and not to some SampleData, meaning XAML expects that this XML file is actually part of the final program. Because of that, the syntax is different: binding to XPATH instead of PATH. And therefore we would have to keep two versions of the XAML file... one for Blend and one for the game. Keeping them in sync is also not very promising.
I hope anyone has some experience and can point me in the right direction.