GithubHelp home page GithubHelp logo

Comments (5)

timunie avatar timunie commented on June 13, 2024

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

from mahapps.metro.iconpacks.

GF-Huang avatar GF-Huang commented on June 13, 2024

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} />

from mahapps.metro.iconpacks.

timunie avatar timunie commented on June 13, 2024

@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. 👍

from mahapps.metro.iconpacks.

GF-Huang avatar GF-Huang commented on June 13, 2024

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:

from mahapps.metro.iconpacks.

timunie avatar timunie commented on June 13, 2024

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

from mahapps.metro.iconpacks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.