Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom WPF within Revit Ribbon

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
NonicaTeam
409 Views, 4 Replies

Custom WPF within Revit Ribbon

Hi,
We were wondering if someone has had experience adding custom XAML/WPF directly to the Revit ribbon creating custom integrated designs, instead of the typical pushbutton or splitbutton. We are aware that this is outside of the supported interfaces of Revit API, but we saw an interesting article from Jeremy Tammick (https://thebuildingcoder.typepad.com/blog/2011/02/pimp-my-autocad-or-revit-ribbon.html)  in which he transformed the Revit UI and he mentions about the black container in the back of the ribbon that could support WPF.
Anyone has an idea on how we could start researching this?

Many thanks

 

4 REPLIES 4
Message 2 of 5

Hi @NonicaTeam,

This thread: https://stackoverflow.com/questions/40096793/best-starting-point-for-wpf-revit-add-in has important lead points you can read and understand when exploring using WPF to create Revit Addins. Kindly, check and see if it helps

Carol Gitonga, Developer Advocacy and Support, ADN Open
Message 3 of 5

Thanks for your reply @caroline.gitonga! However we are not looking to create a WPF window and call it from a button for instance, but we are looking for developing WPF/XAML directly integrated in the Revit UI and implement custom designs out of the supported Pushbuttons, Splitbuttons or Stackbuttons.
I hope this clarifies
Many thanks

Message 4 of 5
RPTHOMAS108
in reply to: NonicaTeam

There are certain aspects you can template with AdWindows in an undocumented way. For example some people ask about ComboBox with a list that can grow or shrink.

 

I used code below to add a single item of ListBox in the normal ComboBox. So in effect it is a ComboBox with one item in it which is a ListBox. It seemed to work ok in 2021 version, I didn't use it that much to be honest but it worked ok when I did.

 

230124.png

 

In the below the object UIItemSearchCriteria is just a class I created to help find the control via Autodesk.Windows.ComponentManager.Ribbon using certain criteria e.g. panel name, tab name, id etc.

 

CBi is the RvtRibbonCombo that has members that templates and binding can be set on.

I'm using

ItemsSourceBinding: Points to a collection of one item containing an object that represents the inserted ListBox

SelectionBoxItemTemplate: In the image above '{Binding Current}' would be pointing to a object property containing the string 'Application'

ItemTemplate: How to form the single item i.e. turn it into a ListBox that has itself binding to items and templates for it. You can then also add events to the code behind of the resource dictionary. If you use such events you would have to implement IExternalEventHandler or could perhaps instead use the built-in ComboBox.DropDownClosed. In my case I used my own event because I wasn't interacting with the document (I was just changing a value in a Ribbon text box).

 

 Private Sub ReDirBindings(SC As UIItemSearchCriteria)
        Dim CBi As UIFramework.RvtRibbonCombo = GetItem(SC)

        If CBi Is Nothing Then Exit Sub Else
        'AddHandler Autodesk.Windows.ComponentManager.

        Dim RD As New ResourceDictionary
        RD.Source = New Uri("pack://application:,,,/RPT_RvtUI_Utils;Component/RT_ResDictionary.xaml", UriKind.Absolute)
        Dim DT As DataTemplate = RD.Item("RPT_DT")
        Dim DT_SB As DataTemplate = RD.Item("RPT_DT_SB")
        If DT Is Nothing OrElse DT_SB Is Nothing Then Exit Sub Else

        Dim Binding0 As New System.Windows.Data.Binding
        Binding0.Source = InternalListOfOneItem

        CBi.SelectionBoxItemTemplate = DT_SB
        CBi.ItemTemplate = DT
        CBi.ItemsSourceBinding = Binding0
    End Sub

 

 

<ResourceDictionary x:Class="RT_ResDictionary"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:RPT_RvtUI_Utils">

    <DataTemplate x:Name="RPT_DT" x:Key="RPT_DT">
        <ListBox x:Name="ListBox_R1" MaxHeight="300" HorizontalContentAlignment="Stretch" 
                 SelectionChanged="ListBox_R1_SelectionChanged" 
                 ItemsSource="{Binding Items}" ItemTemplate="{Binding ListItemTemplate}" 
                 ItemTemplateSelector="{Binding ListItemTemplateSelector}" 
                 BorderThickness="0" BorderBrush="{x:Null}"></ListBox>
        
    </DataTemplate>
    <DataTemplate  x:Name="RPT_DT_SB" x:Key="RPT_DT_SB">
        <TextBlock Text="{Binding Current}"></TextBlock>

    </DataTemplate>

</ResourceDictionary>

 

 Once you have ListBox in place you can then further template it from outside i.e. the above is just a place holder e.g.

 

Private Sub AddTemplates()

        Dim RD As New ResourceDictionary
        RD.Source = New Uri("pack://application:,,,/RPT_XXXXXXX;Component/ResDictionary.xaml", UriKind.Absolute)

        Dim TDict As New Dictionary(Of Macros.MacroLanguageType, DataTemplate)
        TDict.Add(Autodesk.Revit.DB.Macros.MacroLanguageType.VBNet, RD.Item("RT_ITM_VB"))
        TDict.Add(Autodesk.Revit.DB.Macros.MacroLanguageType.CSharp, RD.Item("RT_ITM_CS"))
        TDict.Add(Autodesk.Revit.DB.Macros.MacroLanguageType.Python, RD.Item("RT_ITM_PY"))
        TDict.Add(Autodesk.Revit.DB.Macros.MacroLanguageType.Ruby, RD.Item("RT_ITM_RU"))

        Dim TS As New RT_TemplateSelectorClass(TDict)
        MainProcess.MacroList_App.ListItemTemplateSelector = TS
        MainProcess.MacroList_Doc.ListItemTemplateSelector = TS
End Sub

 

 

Message 5 of 5
NonicaTeam
in reply to: NonicaTeam

Thanks! That is definetely enligthing and helpful. We will explore taking this to c#.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community