How do you know if a collection has been clicked on by the user using Python? How can I create a panel that allows me to add custom properties (StringProperty, BoolProperty, etc) for Collections? I want to show a GUI in the object properties when the user clicks a collection in the outliner. To create a panel you normally inherit from bpy.types.Panel and implement the draw(). The poll() function can be used to determine if the panel should be shown or not. The obvious approach is to use this feature. But how would this poll() look like? How do you know if a collection has been clicked by the user as shown in the screenshot below.

When &quot;my-collection&quot; is clicked/selected I want to show a panel in the object properties. But how do I know  if a collection has been clicked?
Update 1

I'll try to clarify the issue a bit more. In the image above I've made the &quot;Sub&quot; collection active. When I print the name C.collection.name you see that it prints &quot;Sub&quot;.  Now, let me make &quot;Cube&quot; active:

Now, when I print C.collection.name it prints &quot;Sub&quot; again; and although that's correct, that's not the info I'm trying to retrieve. I need to query some other context value which would give me the collection when &quot;Sub&quot; is active and &quot;Cube&quot; when the object is active.
It’s easier than you might think: Either get the collection in context (C.collection) or the collection of the active View Layer (C.view_layer.active_layer_collection). Both attributes return a reference to the selected collection in the Outliner allowing to access the name of the collection by using its name attribute to compare against.
Adding the following poll method to your panel class will only return True in case the selected collection is called MyCollection and thus display the panel:
@classmethod
def poll(cls, context):
    return context.collection.name == &quot;MyCollection&quot;


Code based on ui_panel_simple.py template:
import bpy


class HelloWorldPanel(bpy.types.Panel):
    &quot;&quot;&quot;Creates a Panel in the Object properties window&quot;&quot;&quot;
    bl_label = &quot;Hello World Panel&quot;
    bl_idname = &quot;OBJECT_PT_hello&quot;
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = &quot;object&quot;

    @classmethod
    def poll(cls, context):
        return context.collection.name == &quot;MyCollection&quot;

    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text=&quot;Hello world!&quot;, icon='WORLD_DATA')

        row = layout.row()
        row.label(text=&quot;Active object is: &quot; + obj.name)
        row = layout.row()
        row.prop(obj, &quot;name&quot;)

        row = layout.row()
        row.operator(&quot;mesh.primitive_cube_add&quot;)


def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == &quot;__main__&quot;:
    register()

Further reading:

How to create a custom UI?
What do operator methods do? (poll, invoke, execute, draw &amp; modal)