MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

A binding error occurs when using DialogHost in version 5.2.1

Open darkraise opened this issue 7 months ago • 2 comments

Bug explanation

Bug detail

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:(no path); DataItem=null; target element is 'VisualBrush' (HashCode=25747420); target property is 'Visual' (type 'Visual')

Environment

.NET MaterialDesign
Version 8.0 5.2.1

App.xaml

 <Application
    x:Class="MDTest.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MDTest"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme
                    BaseTheme="Light"
                    PrimaryColor="DeepPurple"
                    SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application> 

MainWindow.xaml

 <Window
    x:Class="MDTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:MDTest"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    Style="{StaticResource MaterialDesignWindow}"
    mc:Ignorable="d">
    <materialDesign:DialogHost>
        <Grid />
    </materialDesign:DialogHost>
</Window>

Other details

Similar to bug https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/issues/3228 happened in version 4.9.0

Version

5.2.1

darkraise avatar Apr 21 '25 04:04 darkraise

I think this is due to the static reference to the converter, which was introduced in #3732: https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/e3c124063ca2978d3af8f52e6dff59804ca71031/src/MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.DialogHost.xaml#L220

corvinsz avatar Apr 21 '25 09:04 corvinsz

Confirm that changing to StaticResource can solve the issue:

<converters:FirstNonNullConverter x:Key="FirstNonNullConverter" />

<!-- deducted -->

<MultiBinding Converter="{StaticResource FirstNonNullConverter}">
    <Binding ElementName="ContentCoverBorder" />
    <Binding Source="{x:Static DependencyProperty.UnsetValue}" />
</MultiBinding>

<!-- deducted -->

darkraise avatar Apr 21 '25 09:04 darkraise