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

How to convert a PackIconMarkup to a Geometry object? #256

Closed
GF-Huang opened this issue Apr 2, 2021 · 5 comments
Closed

How to convert a PackIconMarkup to a Geometry object? #256

GF-Huang opened this issue Apr 2, 2021 · 5 comments

Comments

@GF-Huang
Copy link

GF-Huang commented Apr 2, 2021

C# Code or XAML is fine.

@timunie
Copy link
Contributor

timunie commented Apr 3, 2021

Hi @GF-Huang

I have a PR open which provides an export button to the browser. It is not merged yet but feel free to clone my branch and build the browser on your own. See:

Happy coding
Tim

@GF-Huang
Copy link
Author

GF-Huang commented Apr 3, 2021

I had write a custom MarkupExtension to do this, I hope this will be add into this repo.

public abstract class PackIconGeometryExtension<TKind> : MarkupExtension where TKind : Enum {
    public TKind Kind { get; set; }

    protected abstract IDictionary<TKind, string> DataIndex { get; }

    protected PackIconGeometryExtension() { }

    protected PackIconGeometryExtension(TKind kind) => Kind = kind;

    public override object ProvideValue(IServiceProvider serviceProvider) => Geometry.Parse(DataIndex[Kind]);
}

public class UniconsGeometryExtension : PackIconGeometryExtension<PackIconUniconsKind> {
    protected override IDictionary<PackIconUniconsKind, string> DataIndex => PackIconUniconsDataFactory.DataIndex.Value;

    public UniconsGeometryExtension() { }

    public UniconsGeometryExtension(PackIconUniconsKind kind) : base(kind) { }
}

// and so on..
public class XxxGeometryExtension : PackIconGeometryExtension<PackIconXxxKind> {
    protected override IDictionary<PackIconXxxKind, string> DataIndex => PackIconXxxDataFactory.DataIndex.Value;

    public XxxGeometryExtension() { }

    public XxxGeometryExtension(PackIconXxxKind kind) : base(kind) { }
}

Usage:

<MyButton Geometry={iconPacks:UniconsGeometry Kind=Xxx} />

@timunie
Copy link
Contributor

timunie commented Apr 5, 2021

@GF-Huang tbh at the moment I don't see a good usecase for this. Not all Icons are build the same way, so you would need to take care of this. Some geometries are mirrored, others are outline only, others are filled, etc. So just rutrning the path data may lead to wrong appearance.

Moreover I don't see the the benefit right now. Maybe you can share a sample App via github repro where we can have a look at your extension and the MyButton - Control? Maybe then your point gets clearer or we have an alternative idea for your usecase.

Anyway thank you for the idea. 👍

@GF-Huang
Copy link
Author

GF-Huang commented Apr 5, 2021

Actually I'm using the attach property Iconelement.Geometry from HandyControl, but just to make my suggestion a little bit simpler, I'll just say MyButton. Maybe I replace the `<Path x:Name="PathMain" ... /> to something PackIcon will be better?

reference:

@timunie
Copy link
Contributor

timunie commented Apr 6, 2021

Hi @GF-Huang

what do you think about this?
image

<StackPanel>
    <TextBlock>IconContent-Example</TextBlock>
    <Button Style="{DynamicResource Handy.Styles.Buttons.IconProposal}" Content="Proposal" hc:IconElement.IconContent=":-)"
            Background="Red">
        <hc:IconElement.IconTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}" FontSize="15" FontFamily="Courier New" FontWeight="Bold" />
            </DataTemplate>
        </hc:IconElement.IconTemplate>
    </Button>
    <Button Style="{DynamicResource Handy.Styles.Buttons.IconProposal}" Content="IconPacks Example"
            hc:IconElement.IconPosition="Right"
            hc:IconElement.IconContent="{iconPacks:Material Kind=Teach}"
            Background="BlueViolet" />
</StackPanel>

I know this will lead to some work on your side, but I think this is way more flexible. You can then have any object as Icon, even Images or other controls. Moreover the Icon can change based on buttons content. Your Geometry can also still be used the same way.

I've sent you a draft PR which needs to be reworked on your own. HandyOrg/HandyControl#767

Happy coding
Tim

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

No branches or pull requests

3 participants