Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent colors are added twice #10

Open
Taldrit78 opened this issue Dec 15, 2022 · 2 comments
Open

Recent colors are added twice #10

Taldrit78 opened this issue Dec 15, 2022 · 2 comments

Comments

@Taldrit78
Copy link

The recently used colors are added twice to the ObservableCollection. I saved them and tested it twice, even with the example project. The list then looks like this:
"LastUsedColors": [
{
"Color": "#FFF5F5F5",
"Name": "WhiteSmoke"
},
{
"Color": "#FFF5F5F5",
"Name": "FFF5F5F5"
},
{
"Color": "#FFD3D3D3",
"Name": "LightGray"
},
{
"Color": "#FFD3D3D3",
"Name": "FFD3D3D3"
},
{
"Color": "#FF483D8B",
"Name": "DarkSlateBlue"
},
{
"Color": "#FF483D8B",
"Name": "FF483D8B"
},
{
"Color": "#FF9370DB",
"Name": "MediumPurple"
},
{
"Color": "#FF9370DB",
"Name": "FF9370DB"
},
{
"Color": "#FF8A2BE2",
"Name": "BlueViolet"
},
{
"Color": "#FF8A2BE2",
"Name": "FF8A2BE2"
}
]
}

So as you can see it is always added once with the name and once with the code as name. Maybe the Color should be used to see if it is already inside the list, not the name. I know ColorItem has a nullable Color, but when I pick a color, the method looking into the list if the color is already inside should have a color and if not (null) then it should be ignored and not added.

@Taldrit78
Copy link
Author

Taldrit78 commented Dec 15, 2022

Further informations:
When I try to debug in single step, it doesn't happen. It seems it is happening because the Color_SelectionChanged() adds the color with the correct name and afterwards the CloseColorPicker() adds it with the wrong name and the Equals in the ColorItem object tries to equals by Color AND Name. Maybe it should only check by Color?

I tried it and this would work:

    public override bool Equals(object obj)
    {
        ColorItem ci = obj as ColorItem;
        if (ci == null)
            return false;

        return ci.Color.Equals(Color); // && ci.Name.Equals(Name);
    }

@Dirkster99
Copy link
Owner

It would be great if you could submit a Pull Request that fixes this issue. So, I can better understand your fix and apply it in a new version of the control - I'd be more than happy to help 👍🏽 thanx a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants