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

Cannot change Fluent.Button Icon Dynamically #201

Closed
andirinli opened this issue Nov 17, 2015 · 8 comments
Closed

Cannot change Fluent.Button Icon Dynamically #201

andirinli opened this issue Nov 17, 2015 · 8 comments
Assignees
Labels
Milestone

Comments

@andirinli
Copy link

var btn = BoxPccStatus.Children.OfType<Fluent.Button>().FirstOrDefault(f => (int)f.Tag == pcc.PccNum);

                switch (pcc.PccState)
                {
                    case PccStates.DISCONNECTED:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOffUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOffUri);
                        break;
                    case PccStates.CONNECTED:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    case PccStates.IDLE:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    case PccStates.READY:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    case PccStates.PRINTING:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    case PccStates.INITIALIZING:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    case PccStates.STARTUP:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    case PccStates.FAULT:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOffUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOffUri);
                        break;
                    case PccStates.LOADING:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;
                    default:
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOffUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOffUri);
                        break;
                }

Button Icon is not change why???

@batzen
Copy link
Member

batzen commented Nov 17, 2015

As I don't have all your code I would guess that your button is not found by the tag you search for.
Or do you really hit one of those icon assignment lines?

@andirinli
Copy link
Author

scr

as you can see btn founded
if i use same commands in usercontrol loaded event its working. but if i try in another event its not working (for example another button click event)
and also i try change font size and forecolor from another event its work, but btn.background is not work.

@batzen
Copy link
Member

batzen commented Nov 17, 2015

That's strange.
Could you try to set btn.Icon = null and btn.LargeIcon = null before you assign your values?
That's not meant to be a permanent fix, but I just want to exclude some potential factors.

@andirinli
Copy link
Author

Yes i try.
i creating buttons on usercontrol loaded.
when pcc state chance event triggered; i can change font size, forecolor, header ,etc..
except Background,Icon,LargeIcon

@batzen
Copy link
Member

batzen commented Nov 17, 2015

I think you misunderstood what I want you to try.
Could you modify one of your case blocks to

case PccStates.IDLE:
                        btn.Icon = null;
                        btn.LargeIcon = null;
                        btn.Icon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        btn.LargeIcon = new BitmapImage(Engine.EngineResources.PccOnUri);
                        break;

And tell me if the icon changes.
If that does not work it would be nice if you could provide a repro for your issue. By repro I mean a small sample application which reproduces your issue.

Background is not bound in the style so changing it has no effect. The original developers of this library never took that into account and I never needed it to be changeable.

@andirinli
Copy link
Author

@batzen
Copy link
Member

batzen commented Nov 18, 2015

Ok, i can reproduce it.
But i don't know why it fails to show the images...
Essentially the ObjectToImageConverter, working in the background, just does

var image = new Image
{
    Source = yourBitmapImage
};

If you remove the assignment of btn.Icon and just leave btn.LargeIcon it works, but only for one button...

Everything works fine when you change your code to:

btn.Icon = Engine.EngineResources.PccOnUri;
btn.LargeIcon = Engine.EngineResources.PccOnUri;

Please don't ask me why using "new BitmapImage" for the same Uri causes such an issue.
For me it smells like a WPF issue...

@batzen
Copy link
Member

batzen commented Nov 18, 2015

Ok, it seems like there is some caching going on in WPF internally.
If I change the converter to get a frozen instance of the BitmapImage it works.

@batzen batzen self-assigned this Nov 18, 2015
@batzen batzen added this to the 3.6.1 milestone Nov 18, 2015
@batzen batzen closed this as completed in 09bf141 Nov 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants