MahApps / MahApps.Metro.IconPacks

Awesome icon packs for WPF and UWP in one library
MIT License
1.76k stars 215 forks source link

Icons display errors in XAML designer constantly though build works fine #154

Closed panthernet closed 4 years ago

panthernet commented 4 years ago

Describe the bug When using the icons as described in FAQ a xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" namespace is generated automatically but XAML designer shows following error: Unable to create unknown type "{http://metro.mahapps.com/winfx/xaml/iconpacks}PackIconMaterial" Project works when compiled but XAML designer don't show anything at all because of this error.

To Reproduce ^

Expected behavior No XAML error displayed.

Desktop Environment (please complete the following information):

Additional context Where's no error if I manually use several namespaces in the following format. Usable but not comfortable.

        xmlns:iconPacks="clr-namespace:MahApps.Metro.IconPacks;assembly=MahApps.Metro.IconPacks.MaterialLight"
        xmlns:iconPacks1="clr-namespace:MahApps.Metro.IconPacks;assembly=MahApps.Metro.IconPacks.Material"
punker76 commented 4 years ago

@panthernet Can you please specify which version of IconPacks, Visual Studio and .Net Core 3 you are using? Here is a screenshot from my test build with .Net Core 3.0 final, VS 16.3.5 and MahApps.Metro.IconPacks v3.0.0-alpha0245.

2019-10-16_23h28_39

panthernet commented 4 years ago

Same lib version as yours. I'll try to update VS to latest minor patch to see if something is changing. Looks like the error is not 100% reproducable. Some controls use original namespace just fine but custom ContentControl with a style which uses this namespace produces the error steadily when referenced inside other control.

image

image

image

    public class DialogWrapper: ContentControl, INotifyPropertyChanged
    {
        static DialogWrapper()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(DialogWrapper),
                new FrameworkPropertyMetadata(typeof(DialogWrapper)));
        }

        public static readonly DependencyProperty TitleTextProperty = 
            DependencyProperty.Register( "TitleText", typeof(string),
                typeof(DialogWrapper), new FrameworkPropertyMetadata(null));

        private bool _isWindow;

        public string TitleText
        {
            get => (string)GetValue(TitleTextProperty);
            set => SetValue(TitleTextProperty, value);
        }

        public static readonly DependencyProperty CloseCommandProperty = 
            DependencyProperty.Register( "CloseCommand", typeof(ICommand),
                typeof(DialogWrapper), new FrameworkPropertyMetadata(StaticCommands.CloseDialogCommand));

        public ICommand CloseCommand
        {
            get => (ICommand)GetValue(CloseCommandProperty);
            set => SetValue(CloseCommandProperty, value);
        }

        public bool IsWindow
        {
            get => _isWindow;
            set { _isWindow = value; OnPropertyChanged(); }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

        }
    }
    <Style TargetType="{x:Type local:DialogWrapper}">
        <Setter Property="Padding"
                Value="10" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:DialogWrapper}">
                    <Border BorderThickness="1" BorderBrush="{DynamicResource MahApps.Brushes.Accent}"
                            Background="{DynamicResource MahApps.Brushes.Window.Background}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="35"/>
                                <RowDefinition/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Border Background="{DynamicResource MahApps.Brushes.WindowTitle}">
                                <Grid>
                                    <StackPanel Orientation="Horizontal">
                                        <iconPacks:PackIconMaterial Kind="RssBox" Width="28" Height="28" Margin="3" VerticalAlignment="Center"
                                                                    Foreground="{DynamicResource MahApps.Brushes.White}"/>
                                        <Label Foreground="{DynamicResource MahApps.Brushes.White}" Content="{TemplateBinding TitleText}" Margin="5" Padding="0"
                                               VerticalAlignment="Center" FontSize="18" mah:ControlsHelper.ContentCharacterCasing="Upper"/>
                                    </StackPanel>
                                    <Button Margin="3" HorizontalAlignment="Right" Padding="0" Style="{DynamicResource CloseButtonStyle}"
                                            Focusable="False" Command="{TemplateBinding CloseCommand}">
                                        <iconPacks:PackIconMaterial Kind="CloseBoxOutline" Width="28" Height="28" />
                                    </Button>
                                </Grid>
                            </Border>
                            <ContentPresenter Grid.Row="1" 
                                              Content="{TemplateBinding Content}"
                                              Margin="{TemplateBinding Padding}"/>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
punker76 commented 4 years ago

@panthernet Can you publish this sample?

panthernet commented 4 years ago

Also don't forget to enable XAML UI designer when navigating MainWindow XAML code.

SampleApp.zip

punker76 commented 4 years ago

@panthernet Thx, I'll look what's wrong.

punker76 commented 4 years ago

@panthernet I got it and will raise a PR. It's again the designer who can't handle generic classes.

2019-10-17_21h34_50