The application UI is data-template based, with templates customizable for different data types. Templates are located in source/RevitLookup/Styles/ComponentStyles/ directory.
RevitLookup uses a shared UI approach where Views are defined in RevitLookup.UI.Framework and used in both Revit and Playground environments.
When adding a new window or page:
- Define a ViewModel interface in
RevitLookup.Abstractions. - Implement the interface twice:
- Revit implementation: in
RevitLookup.ViewModels, providing real data from the Revit API. - Playground implementation: in
RevitLookup.UI.Playground.Mocks.ViewModels, providing mock or sample data.
- Revit implementation: in
- Registration in the DI container is not required; views and ViewModels are automatically registered via Scrutor.
To customize the display of a specific type:
- Create a DataTemplate in a XAML file within the ComponentStyles directory:
// source/RevitLookup/Styles/ComponentStyles/ObjectsTree/TreeGroupTemplates.xaml
<DataTemplate
x:Key="DefaultSummaryTreeItemTemplate"
DataType="{x:Type decomposition:ObservableDecomposedObject}">
<ui:TextBlock
FontTypography="Caption"
Text="{Binding .,
Converter={x:Static converters:DescriptorFormattingConverters.ObjectDisplayText},
Mode=OneTime}" />
</DataTemplate>- Add a selector rule in the
TemplateSelectorclass:
// source/RevitLookup/Styles/ComponentStyles/ObjectsTree/TreeViewItemTemplateSelector.cs
public sealed class TreeViewItemTemplateSelector : DataTemplateSelector
{
/// <summary>
/// Tree view row style selector
/// </summary>
public override DataTemplate? SelectTemplate(object? item, DependencyObject container)
{
if (item is null) return null;
var presenter = (FrameworkElement) container;
var decomposedObject = (ObservableDecomposedObject) item;
var templateName = decomposedObject.RawValue switch
{
Color => "SummaryMediaColorItemTemplate",
_ => "DefaultSummaryTreeItemTemplate"
};
return (DataTemplate) presenter.FindResource(templateName);
}
}For custom visualization of specific data types, create specialized templates following the pattern above and register them in the appropriate style selectors.