Skip to content

Please add Command implementation sample for creating own Control Librarys with Templated Control Template-File #19156

Open

Description

@DevTKSS

What would you like clarification on

Current Page: https://github.com/unoplatform/uno/blob/master/doc/articles/guides/how-to-create-control-libraries.md/#L1

The current Example is only including Text setting and I would like to create a own Control that would also contain a Button/AppBarButton, which should be bindable also, but when I am trying to implement the CanExcecute of the DependencyProperty Command typed to ICommand, it wants me to initialize this Command in the constructor, to be able to listen to changes. Maybe that would be done with a eventhandler correctly (looked up the AppBarButton Definition where a private readonly SerialDisposable is used...
I would "simply" like to set the IsEnabled Property from that Button from the CanExecute...

Thats why I would like clarification on this.

Concern

Developing with Uno

Affected platforms

WebAssembly, Android, iOS, Mac Catalyst, Skia (WPF), Skia (Linux X11), Skia (macOS), Skia (Linux Framebuffer), Skia (GTK), Windows (WinAppSDK)

Any feedback?

Especially for those (like me) who are using mvux this topic is maybe harder to understand than for mvvm users who are creating these Commands every time they writing their ViewModel Code which is generated in mvux.

Activity

  1. added
    difficulty/tbd
    triage/untriaged
    on Jan 5, 2025
  2. MartinZikmund commented on Jan 6, 2025

    @MartinZikmund
    Member

    @DevTKSS You should be able to create a dependency property with ICommand type and then just detach from the previous value/attach to the new value's CanExecuteChanged event to listen to when CanExecute should be called on the instance set there - and then apply the required property like IsEnabled

  3. added
    project/documentation 📖
    difficulty/medium 🤔
    difficulty/starter 🚀
    and removed
    triage/untriaged
    difficulty/tbd
    difficulty/medium 🤔
    on Jan 6, 2025
  4. DevTKSS commented on Jan 6, 2025

    @DevTKSS
    ContributorAuthor

    Hm okay, will try this. Does that also apply to ICommand Bindings in case of viewModels? Like if I would listen to a CanExcecuteChanged of a command property there? Or would I need to detach before resetting that private Property on my View Datacontext Changed?

  5. DevTKSS commented on Oct 3, 2025

    @DevTKSS
    ContributorAuthor

    @Xiaoy312 just scrolling and possible closing as already solved through issues I opened on my learning path...
    what would you think about this idea of mine to help those beginners with that kind of things like me getting started with this in our uno apps:

    You explained to me on the toolkit Discussion thread with sample code, how I could for example create DependencyProperty's with

    • using that DynamicDependency Attribute, which I would not directly remember to have seen or got explained on the linked ms docs 🤔👀

    • how to use a DependencyProperty with ICommand & how to correctly register for existing events/maybe calling our own events if needed that could be listened to, to then enabling bind-able control definitions especially if we might be using mvux where we normally avoid Codebehind and (e.g. me) did not learn mvvm before😅🤷 the ms docs are just told me that days I readed through this linked docs, how to use that basic Property for callback 🤔

    • interesting also would be to get told what we might can do with the uno provided DisposableDependencyPropertyCallback and its overloads that are available in the Codebehind for example of a simple Page. What should we maybe know to better decide which of them to use and if applying, which different behaviors should we expect from it? Maybe the disposable one is better to be used in mvux looking to the updating part of mvux 🤔 I would assume it is disposing the old page when sending us the updated new one, so a disposable definition might be then the better choice 🤷

    • We should optimally be told in the docs, that we are not recommended to have CommunityToolkit.Mvvm + Mvux in the same project and then should instead add a Library Project, as I was told on discord from Jeromé after I had trouble with Hot Reload + trying to use mvux for my own control definition, but I never seen this limitation stated on the docs.

    Learning by failing makes of course not the best experience, so we could maybe improve this a slightly bit 👍
    There are so much cool things we could use in uno apps specifically that are not told about and not available if we use ms things only, that it would be helpful to get some more information and guidance for it into the docs, not only by asking on discord or here and then beeing told... Would maybe also ease the effort for the team to then just link us to there🤷

    What do you think, is this a considerable enhancement that could be planned to get into the uno docs for this topic?

  6. github-actions commented on May 10, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  7. added
    stale
    on May 10, 2026
  8. removed
    stale
    on May 11, 2026
  9. MartinZikmund commented on May 18, 2026

    @MartinZikmund
    Member

    Thanks for the detailed write-up @DevTKSS - this is a fair request. Adding an ICommand-typed DependencyProperty example (with CanExecuteChanged wiring via SerialDisposable, like AppBarButton does internally) to the how-to-create-control-libraries guide would meaningfully help folks building templated controls, especially MVUX users who don't get commands generated for them. Keeping this open and marking it as a good docs starter task - the issue already has kind/documentation and difficulty/starter labels, so it's well-suited for a community contribution. The broader guidance points you raised (CommunityToolkit.Mvvm + MVUX coexistence, DisposableDependencyPropertyCallback usage) are worth separate focused doc issues so each can be addressed cleanly.

  10. github-actions commented on Sep 16, 2026

    @github-actions
    Contributor

    This issue has had no activity for 120 days. It will be closed in 10 days if there is no further activity. Remove the Stale label or leave a comment to keep it open.

  11. added
    stale
    on Sep 16, 2026
  12. adarsh6980 commented on Sep 24, 2026

    @adarsh6980
    Contributor

    Hi! I'd like to work on this. Following Martin's suggestion above, I plan to add an ICommand-typed DependencyProperty example to the control libraries guide, showing how to wire up CanExecuteChanged with SerialDisposable the way AppBarButton does internally. Could this be assigned to me?

  13. removed
    stale
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/starter 🚀kind/documentationproject/documentation 📖

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions