6

I'm trying to show a popup to edit a brand in my app but it doesn't show up.

Function where I call the Dialog:

private async Task EditBrandAsync(Brand brand)
{
    var dialog = new ContentDialogs.EditBrandDialog(brand);
    await dialog.ShowAsync();
}

ContentDialog XAML:

<ContentDialog
    x:Class="xizSoft.ContentDialogs.EditBrandDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:xizSoft.ContentDialogs"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <StackPanel>
        <TextBlock Text="Marca" Style="{StaticResource SubheaderTextBlockStyle}"/>

        <TextBox Header="Nome" Text="{Binding Name}"/>
        <TextBox Header="Logotipo" Text="{Binding LogoFileName}"/>

        <StackPanel>
            <Image Source="{Binding LogoFileName}"/>
        </StackPanel>
    </StackPanel>
</ContentDialog>

Code-behind:

namespace xizSoft.ContentDialogs
{
  public sealed partial class EditBrandDialog : ContentDialog
    {
        public Brand _brand {get; set;}

        public EditBrandDialog(Brand brand)
        { 
            this.InitializeComponent();
            this.DataContext = _brand = brand;
        }
    }
}

I've already tryied do debug and the content dialog is being called so I dont know why it isn't showing up.

mm8
  • 163,881
  • 10
  • 57
  • 88
David Simões
  • 303
  • 4
  • 11

1 Answers1

8

Make sure that the SubheaderTextBlockStyle resource is in scope and that you set the XamlRoot property of the ContentDialog:

private async Task EditBrandAsync(Brand brand)
{
    var dialog = new ContentDialogs.EditBrandDialog(brand);
    dialog.XamlRoot = this.Content.XamlRoot;
    await dialog.ShowAsync();
}
mm8
  • 163,881
  • 10
  • 57
  • 88
  • 1
    This works. But why must the XamlRoot property be set? That is not a requirement when using ContentDialogs in UWP – Olumide Oyetoke Jun 28 '22 at 15:57
  • 1
    (Microsoft.UI.Xaml.Controls) ContentDialog is supported, but you must set its XamlRoot property. See ContentDialog, and Popup. https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/winui3#contentdialog-and-popup – Noorul Oct 10 '22 at 14:38
  • mm8's answer is good. I had a further issue where the Styles xaml file was not set to Build Action:Page. – 27k1 Jun 30 '23 at 14:26