fluentribbon / Fluent.Ribbon

WPF Ribbon control like in Office
http://fluentribbon.github.io
MIT License
2.48k stars 515 forks source link

Button Icon #1186

Closed hamidasadi-git closed 6 months ago

hamidasadi-git commented 6 months ago

Hi, I'm new to Fluent.Ribbon. I am trying to use an icon from the Resources folder. I created a folder named "resources" and added some PNG files. After selecting them and changing the build action to "Resources," I noticed that at runtime, the icon displays properly, but at design time, I see a red circle with an "x" on it. The initial code looks like this:

 <Fluent:RibbonTabItem Header="Home">
     <Fluent:RibbonGroupBox Header="Import" Width="210" Margin="0,20">
         <Fluent:Button Header="LoadData" Width="100" Icon="Resources/UploadData.png">
         </Fluent:Button>
     </Fluent:RibbonGroupBox>
</Fluent:Ribbon>

Afterward, I used a trick to fix this issue with the following code. However, I would like to know if it's possible to use the initial code or if there's a design-time bug or etc.?

 <Fluent:RibbonTabItem Header="Home">
     <Fluent:RibbonGroupBox Header="Import" Width="210" Margin="0,20">
         <Fluent:Button Header="LoadData" Width="100">
             <Fluent:Button.Icon>
                 <Image Source="Resources/UploadData.png"  Height="50" />
             </Fluent:Button.Icon>
         </Fluent:Button>
     </Fluent:RibbonGroupBox>
</Fluent:Ribbon>

Environment

hamidasadi-git commented 6 months ago

Also, I have another problem when trying to use a larger button. Even after using the code provided in the previous message, I still see the button like this.

Untitled

batzen commented 6 months ago

To get resources (images) working all the time you should use the pack syntax, as you would when using vanilla WPF. Just using a path, without the pack syntax, won't use the embedded resource icon when used on a Image. It only works for controls from Fluent.Ribbon because there is a special converter that takes care of transforming it.

~You can force a different icon size by setting RibbonProperties.IconSize to Custom.~ Just noticed this won't work as there is currently no way to also set CustomSize on the used IconPresenter...

hamidasadi-git commented 6 months ago

Thank you for your help.