WPF C# Custom Control issue

Joined
Feb 9, 2023
Messages
16
Programming Experience
10+
Good evening,
i have a issue i created custom button control,
and used
xmlns:Icon="http://metro.mahapps.com/winfx/xaml/iconpacks"

and i am getting ( Icon properety was already registerd by MenuButtons ) menubuttons is the name of my user control,

code
WPF:
<UserControl x:Class="Project_Alice.UserControls.MenuButton"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Project_Alice.UserControls"
             xmlns:Icon="http://metro.mahapps.com/winfx/xaml/iconpacks"
             mc:Ignorable="d"
             d:DesignWidth="100"
             Name="menuButton">

    <Button Style="{StaticResource menuButton}">
        <Grid ClipToBounds="True">
            <Ellipse Width="100"
                     Height="100"
                     Fill="Gray"
                     Margin="-190 -30 0 0">

                <Ellipse.Style>
                    <Style TargetType="Ellipse">
                        <Setter Property="Visibility" Value="{Binding Path=Tag,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Button}}}"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding ElementName=menuButton,Path=IsActive}" Value="true">
                                <Setter Property="Visibility" Value="Visible"/>
                                
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Ellipse.Style>
                
                
            </Ellipse>

            <Icon:PackIconMaterial Kind="{Binding ElementName=menuButton, Path=Icon}" Style="{StaticResource menuButtonIcon}"/>


        </Grid>
    </Button>
    
    
</UserControl>

MenuButton Code Behind:
 public PackIconMaterialKind Icon
        {
            get { return (PackIconMaterialKind)GetValue(IconProperty); }
            set { SetValue(IconProperty, value); }
        }

        public static readonly DependencyProperty IconProperty =
            DependencyProperty.Register("Icon", typeof(PackIconMaterialKind), typeof(MenuButton));



        public bool IsActive
        {
            get { return (bool)GetValue(IsActiveProperty); }
            set { SetValue(IsActiveProperty, value); }
        }

        public static readonly DependencyProperty IsActiveProperty =
            DependencyProperty.Register("IsActive", typeof(PackIconMaterialKind), typeof(MenuButton));



Main WPF
<!--Menu Buttons-->
<uc:MenuButton Icon="AbTesting" IsActive="True"/>


App Style
WPF:
        <Style x:Key="menuButton" TargetType="Button">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Foreground" Value="#edeeee"/>
            <Setter Property="Height" Value="40"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Margin" Value="0 12"/>
            <Setter Property="Tag" Value="Hidden"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Border Background="{TemplateBinding Background}">
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>


            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="#7368ff"/>
                    <Setter Property="Tag" Value="Visible"/>
                </Trigger>


                <DataTrigger Binding="{Binding ElementName=menubutton,Path=IsActive}" Value="True">
                    <Setter Property="Foreground" Value="#7368ff"/>
                    <Setter Property="Tag" Value="Visible"/>

                </DataTrigger>
                
            </Style.Triggers>

        </Style>


        <Style x:Key="menuButtonIcon" TargetType="Icon:PackIconMaterial">
            <Setter Property="Width" Value="18"/>
            <Setter Property="Height" Value="18"/>
            <Setter Property="HorizontalAlignment" Value="Center"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="Foreground" Value="{Binding Path=Foreground,RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Button}}}"/>
            
        </Style>
 
Do you get the same error is you name it "CustomIcon"?
 
Do you get the same error is you name it "CustomIcon"?

Yes that made it work now isactive is throwing error
true is not a valid value for property elfisactive
i tryied to change isactive to elfisactive to see if this would resolve the issue as it did for the icon but still telling me its not a valid value cant see how as its setup as a bool
 

Latest posts

Back
Top Bottom