Icon not displayed for RibbonMenuItem - wpf

I have the following code inside a RibbonSplitButton (which rendered correctly on the 3.5 ribbon CTP verion). I tried to view it using the WPF Ribbon 4.0 library, but it's just not rendering the Icon. Any idea why?
<ribbon:RibbonMenuItem Header="Option 3 - icon">
<ribbon:RibbonMenuItem.Icon>
<Image Width="16" Height="16" Source="Images/wizard-icon16.png"></Image>
</ribbon:RibbonMenuItem.Icon>
</ribbon:RibbonMenuItem>

Don't use the Icon property, that is inherited from MenuItem, and isn't used by the Ribbon control. Use the ImageSource property instead.

I also see the same problem. I've try to put even simple text in the Icon property but it just does not show anything.
I've check the control template and there is just no binding to the Icon property in it. You can use ImageSource to put an image in the menu item icon's place.
I guess it simply bad control template.

Add a forward slash in front of Images and do a Rebuild Solution. This is assuming the Images directory is located at the root of your project.
Is the image's build action set to Content?
HTH

Try setting the image's build action to Resource

Related

TabControl staticresource path icons dissapear on tab's switch

I don't seem to find an answer how to make reusable path-icons in wpf. I suspect that my problem is the same with using Image visuals instead of Source but can't figure out how to fix this for Paths.
I have a tab control with separate custom controls in the tabs. Each of them have buttons with 'path' content.
<Button Style="{StaticResource ButtonIconStyle}"
Content="{StaticResource RefreshIcon}"
Command="{Binding RefreshCommand}"/>
Where icon is:
<Path x:Key="RefreshIcon" Stretch="Uniform"
Fill="{StaticResource ButtonIconColor}" Data="..."/>
I need this Uniform stretch so I also tried ViewBox, but that didn't help.
The first tab with this icon I open is shown normally (it can be any tab, not first in tabcontrol). But after switching to another tab with the same defined button and switching back to prev tab the icon in the first one is no longer visible. It happend only with icons that are the same (if icon is not present in the second tab it will remain visible).
What can I do about it?
Btw my Buttons are styled, but the same thing happend when they were just simple rectangular buttons with path content.
The problem is that your path is referenced using StaticResourceExtension in multiple places (by different instances of Button). Since Path is a FrameworkElement and it can only occur once in the visual tree, what happens is if you load the second tab (thus loading the Path into this tab, it gets unloaded from the previous tab (to satisfy the said condition). Observe that it will always be visible in the last tab selected.
In order to resolve this problem you need to set x:Shared="False" on your Path in the resources dictionary - this way whenever it is referenced using StaticResouceExtension a copy will be returned rather than the actual instance from the resources dictionary, each of which will be loaded and stay in the visual tree as expected.

WPF Ribbon Tab view in Designer

I'm using "Microsoft Ribbon for WPF" and creating multiple RibbonTab. I cannot figure out a way to view/focus different tabs in the designer and it by default show the "Home" tab. To see design/xaml changes I made to tabs other than the "Home" tab, I have to debug the project every time and click through the tabs, which is not very convenient. Or I can command out the tab xaml I want to to ignore. Anyone body out there has a solution?
You can also use the SelectedIndex property on the Ribbon to set which tab is the currently selected tab (0 being the first tab, 1 being the second, etc.)
<ribbon:Ribbon SelectedIndex="0" />
The only way I have found is to set the Selector.IsSelected property to true. This will cause the tab to become visible at design time.
<ribbon:RibbonTab Selector.IsSelected="True" ...
I can't confirm this is working right now because my preview in general is not working properly, but this works in general in WPF when trying to hide something at design time only.
Include the namespace for blend
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Then in the element you want to hide use d:IsHidden="True". This will only affect design time, which eliminates the problem of forgetting to change the selected index to the correct value before building.

Alternative to FindAncestor RelativeSource in Silverlight 4 to bind to a property of the page

FindAncestor RelativeSource only supports 'Self' and 'TemplatedParent',
but I have to bind the width of a popup to the width of the page.
Giving the page a name causes problems because sometimes it will
throw exceptions saying a control with that name is already present in the visual tree.
<Popup IsOpen="True"
Width="{Binding ElementName=BordPage, Path=Width}"
Height="{Binding ElementName=BordPage, Path=Height}">
Background information:
I'm using a SL4 navigation based application here. BordPage is a navigation page,
which I'm using multiple times within the application. So giving it a name in the page itself is not really a good idea,
but I don't know how else I can bind to the width and height of the page.
What I'm trying to do is have a black border (with opacity 0.8) cover the entire screen,
(including the controls of the MainPage). Then on top of that I want to display some other controls.
Since the application is touch controlled, providing the user with a ComboBox to select a value doesn't really work wel. Instead I want to show this black overlay window with a listbox taking up most of the screen so the user can simply touch the value he wants with a single click.
Update: I just realized I can use the ChildWindow class to do this.
But my original question remains.
My general solution for this problem is by writing a custom behavior. It's not a pure XAML solution but it gives you a lot more flexibility.
Create a behavior that searches up the VisualTree to find the right item and then have it set the width of the Popup correctly.
It may be a little more complicated than a straight binding but it avoids all the naming issues.
Put the following in the constructor of your control so you can avoid naming it:
DataContext = this;

Image button Custom Control, silverlight

I am trying to build the Image button by setting
<Button.Content>
<Image Source="..."/>
</Button.Content>
Everything is Fine but i am not able to set the Visual States when button is clicked i wanted to something like Flash on top of button (Blue Purple Theme).
One more thing I need to create around 10 such button with different Images I think Custom Control works fine.
Any help is appretiated.
Thanks
Lavanya
You'll want to re-template your Button(s) and wrap that up into a Style.
http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx
Then use the VisualStateManager (easiest from within Blend 3) to change the visual properties on various states.
http://silverlight.net/learn/tutorials/stylestemplatesvsm-cs/

Using a XAML vector image as a window icon

LearnWPF.com posted this article about converting bitmap images to XAML and using them in your applications.
The outer element of the XAML image is a Canvas. However, the Window.Icon property only accepts an ImageSource object. Does anyone know how I can 'wrap' the Canvas in an ImageSource so I can use it as a window icon?
Alternatively, is there a better way to use a XAML image as a window icon?
The WPF window Chrome(header bar, Icon etc) are part of the typical Win32 Window system. So it was not built to use with Vector Icon, you need to specify an .Ico, .png or some other supported image file to the Window.Icon property.
But if you really want to make a Vector(XAML) animating Icon, you need to think about the concept of Chrome less window. That means gets rid of the old style window chrome(WIndowStyle="None") and build our own chrome entirely with WPF, then you can place your Vector directly over the left top corner and it will just work as you do with any other XAML Visuals in the application.
Read more about how to create Chromeless window on bellow links
How do I implement a chromeless window with WPF?
Creating a Custom Window in WPF

Resources