1

To install the TeachingTip-control in my UWP app, I've done the following stepts:

  1. installed Microsoft.UI.Xaml package via Nuget in my project
  2. Added <XamlControlsResources xmlns = "using:Microsoft.UI.Xaml.Controls" /> into App.xaml.
  3. Imported Namespace xmlns:controls="using:Microsoft.UI.Xaml.Controls"

I implemented the TeachingTip-control as follows:

<Button x:Name="BackButton"
        Background="{x:Null}"
        Content="Back"
        Click="BackButton_Click">
    <Button.Resources>
        <controls:TeachingTip x:Name="ToggleThemeTeachingTip"
                              Target="{x:Bind BackButton}"
                              Title="Change themes without hassle"
                              Subtitle="It's easier than ever to see control samples in both light and dark theme!"
                              CloseButtonContent="Got it!">
        </controls:TeachingTip>
    </Button.Resources>
</Button>

<Button x:Name="TeachingTipButton"
        Click="TeachingTipButton_OnClick">
</Button>


private void TeachingTipButton_OnClick(object sender, RoutedEventArgs e)
{
    ToggleThemeTeachingTip.IsOpen = true;
}

When I call the function I get the following DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION error (probably UI error), which I do not understand:

enter image description here

What could be the problem? Why does not my code work?

Edit: I have now determined that the error is due to App.xaml. After I've installed the Nuget package Microsoft.UI.Xaml, it's expected to add the following code in App.xaml: enter image description here

But I have already in App.xaml other settings and resources: enter image description here

When I try to add only the line in App.xaml a key error occurs:

<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>

If I give the resource entry a key like this:

<XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" />

 It comes to a completely different error:

Windows.UI.Xaml.Markup.XamlParseException: "The text for this error is not found.

Can not find a Resource with the Name / Key TeachingTipBackgroundBrush

How can I properly add the resource <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/> correctly in my App.xaml?

Ramosta
  • 626
  • 1
  • 7
  • 29

3 Answers3

1

Your App.xaml file needs to look like this:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
        </ResourceDictionary.MergedDictionaries>
        <!-- Other styles here -->
        <Style TargetType="Button">
          ...
        </Style>
    </ResourceDictionary>
</Application.Resources>
coldandtired
  • 993
  • 1
  • 10
  • 13
0

I pasted your code into my project and it worked. However, the code you provided above doesn't have Content for the triggering button, so the only button which appears is the top button. Are you sure you're not failing because of code in BackButton_Click rather than TeachingTipButton_OnClick?

You can remove the duplicate reference to Microsoft.UI.Xaml.Controls from Application.Resources

Josh
  • 4,009
  • 2
  • 31
  • 46
  • It is not due to the function failure. The button events work well and I have no duplicates in app.xaml. I think I have a syntax error in my app.xaml. – Ramosta Jun 21 '19 at 07:18
0

I solved my problem by removing ContentDialog Size style and Default Button style so that <Application.Resources> has only <XamlControlsResources x: Key = "XamlControlsResources" xmlns = "using: Microsoft.UI.Xaml.Controls" /> as a single entry. In my case, multiple entries in <Application.Resources> </Application.Resources> are unfortunately not accepted.

Ramosta
  • 626
  • 1
  • 7
  • 29