Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templated XAML controls for WinUI 3 C# #3868

Open
get-flat opened this issue Dec 28, 2020 · 10 comments
Open

Templated XAML controls for WinUI 3 C# #3868

get-flat opened this issue Dec 28, 2020 · 10 comments
Labels
documentation An issue with existing documentation or a request for documenation of a new topic product-winui3 WinUI 3 issues team-Markup Issue for the Markup team

Comments

@get-flat
Copy link

Describe the bug

Exception on InitializeComponent:
Exception thrown at 0x75A246D2 in BgLabelControlApp.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x02DBDE68.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Follow instructions: https://docs.microsoft.com/en-us/windows/apps/winui/winui3/xaml-templated-controls-csharp-winui-3

Expected behavior

No crash
Update documentation to provide working example

Screenshots

Version Info

Version 16.9.0 Preview 2.0 (vanilla C# only installation - https://docs.microsoft.com/en-us/windows/apps/winui/winui3/)

NuGet package version:
[Microsoft.WinUI 3.0.0-preview3.201113.0]

Windows app type:

UWP Win32
No Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041)
November 2019 Update (18363) Yes
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

Please fix documentation: Generic.xaml is autogenerated when new CustomControl is added.
Please update documentation: "Name the new control "BgLabelControl" and click Add. This will add two new files to your project. BgLabelControl.cs contains the code-behind for the control." What should be the other file? Only .cs file is created.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Dec 28, 2020
@YuliKl YuliKl added documentation An issue with existing documentation or a request for documenation of a new topic product-winui3 WinUI 3 issues labels Dec 28, 2020
@get-flat
Copy link
Author

May be duplicate of: #3657
Could you please update documentation that even for the most basic examples from your documentation you have to apply hacky workarounds.

@StephenLPeters
Copy link
Contributor

@get-flat are you testing on preview 2 or 3? The version info states both :)

@StephenLPeters StephenLPeters added needs-author-feedback Asked author to supply more information. and removed needs-triage Issue needs to be triaged by the area owners labels Jan 5, 2021
@ghost ghost added the no-recent-activity label Jan 12, 2021
@ghost
Copy link

ghost commented Jan 12, 2021

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

@get-flat
Copy link
Author

@StephenLPeters I'm using version [Microsoft.WinUI 3.0.0-preview3.201113.0]
(16.9.0 Preview 2.0, I mean Preview 2 of Visual Studio version 16.9.0. I wasn't sure if VS ver is relevant)

@ghost ghost added needs-triage Issue needs to be triaged by the area owners and removed needs-author-feedback Asked author to supply more information. no-recent-activity labels Jan 12, 2021
@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Jan 13, 2021
@StephenLPeters
Copy link
Contributor

StephenLPeters commented Jan 13, 2021

@evelynwu-msft FYI

@evelynwu-msft
Copy link
Contributor

@get-flat Thanks for your report! The exception you're seeing is known and non-fatal; execution can be safely continued past it. Alternatively, if you find it too noisy, you can disable the winrt::check_hresult exception in Visual Studio's Exception Settings window.
image

I'll talk to our writer and see about getting the sample documentation updated to correct the errors you identified.

@drewbatgit
Copy link

The sample documentation has been updated to note that:

  1. BgLabelControl.cs is the only file generated when you add Custom Control to the project
  2. Generic.xaml is automatically generated when you add the control, so you don't need to manual create it, just update the contents.

@Herdubreid
Copy link

The good news is that I don't get an Exception, the downside however is that I can't get this to work at all.

Also, isn't there something missing for this handler to be called? (I assume the curly bracket repeat is just a typo):

private static void OnLabelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    {
        BgLabelControl labelControl = d as BgLabelControl; //null checks omitted
        String s = e.NewValue as String; //null checks omitted
        if (s == String.Empty)
        {
            labelControl.HasLabelValue = false;
        }
        else
        {
            labelControl.HasLabelValue = true;
        }
    }
}

My project:
https://github.com/Herdubreid/BgLabelControlApp

@drewbatgit
Copy link

Thanks for catching this. In order for the changed handler to be invoked you have to register the callback:

DependencyProperty LabelProperty = DependencyProperty.Register(
            nameof(Label), 
            typeof(string),
            typeof(BgLabelControl), 
            new PropertyMetadata(default(string), new PropertyChangedCallback(OnLabelChanged)));

The article has been updated with this change (and the superfluous brackets have been removed). Thanks again!

@Herdubreid
Copy link

Thanks for clearing that up @drewbatgit

I can successfully set a breakpoint on the handler, so the property is definitely updated.
I can't however get it to show up.

You can check my code here: https://github.com/Herdubreid/BgLabelControlApp

@bpulliam bpulliam added the team-Markup Issue for the Markup team label Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation An issue with existing documentation or a request for documenation of a new topic product-winui3 WinUI 3 issues team-Markup Issue for the Markup team
Projects
None yet
Development

No branches or pull requests

7 participants