This is a migrated thread and some comments may be shown as answers.

Issue setting Icon on RadContextMenu

5 Answers 146 Views
Navigation
This is a migrated thread and some comments may be shown as answers.
Ravin
Top achievements
Rank 1
Ravin asked on 01 Oct 2015, 04:11 PM

Using this example as a base, I created a custom class to add a special right click menu onto any RadGridView item:

Example: https://github.com/telerik/xaml-sdk/blob/master/GridView/CopyPasteFunctionality/GridViewClipboardContextMenu.cs

Code:

 

public GridViewCopyContextMenu(RadGridView grid)
{
    this.gridView = grid;
 
    Image iconCopy = new Image() {
        Stretch = Stretch.None,
        Source = new BitmapImage(new Uri("/Images/copyIcon.png", UriKind.RelativeOrAbsolute))
    };
 
    this.contextMenu = new RadContextMenu();
    this.contextMenu.Items.Add(new RadMenuItem() { Header = GridViewCopyContextMenu.COPY_SELECTED_CELL_WITHOUT_HEADER_HEADER });
    this.contextMenu.Items.Add(new RadMenuItem() { Header = GridViewCopyContextMenu.COPY_SELECTED_CELL_WITH_HEADER_HEADER });
    this.contextMenu.Items.Add(new RadMenuItem() { Header = GridViewCopyContextMenu.COPY_SELECTED_ROW_WITHOUT_HEADER_HEADER });
    this.contextMenu.Items.Add(new RadMenuItem() { Header = GridViewCopyContextMenu.COPY_SELECTED_ROW_WITH_HEADER_HEADER });
    this.contextMenu.Items.Add(new RadMenuItem() { Header = GridViewCopyContextMenu.COPY_ALL_ROW_WITHOUT_HEADER_HEADER });
    this.contextMenu.Items.Add(new RadMenuItem() { Header = GridViewCopyContextMenu.COPY_ALL_ROW_WITH_HEADER_HEADER });
 
    this.contextMenu.Opened += RadContextMenu_Opened;
    this.contextMenu.ItemClick += RadContextMenu_ItemClick;
 
    RadContextMenu.SetContextMenu(this.gridView, this.contextMenu);
}

If I modify any single item to add "Icon = iconCopy, " into the properties, I get the following runtime error:

Category: ParserError
Message: Failed to assign to property 'System.Windows.Controls.ContentPresenter.Content'.

I've tried using "/Images/copyIcon.png" and "MyProject;component/Images/copyIcon.png"; the end result is the same. If I put the source with the either format in xaml on a RadContextMenu, I can see the actual intended image during design time, but I get the same runtime error during runtime.

 

What can I do to fix this so my icon will show? I am using Silverlight 5, on Runtime Version v4.0.30319, with Telerik Version 2014.1.224.1050.

 

Thanks

5 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 05 Oct 2015, 02:01 PM
Hi Ravin,

Using the provided code-snippet we tried to reproduce the observed by you error but it seems everything works as expected on our side - please, check the attached video and let us know if we didn't miss something.

We are familiar with that error, however it was only reproducible with SL4. Using SL5 (the version you are using) everything should works as expected. Could you please try to isolate the error in SL5 and send it back to us - thus we could be able to continue our investigation?

We are looking forward to hearing from you.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Ravin
Top achievements
Rank 1
answered on 05 Oct 2015, 03:53 PM

I did confirm that the version is Silverlight 5, the assembly versions you were using were the same, I did see your Image had Width and Height set instead of Stretch, so I changed mine, but I'm still getting the same error.

 

This is what I found:

Exception: System.Exception {MS.Internal.WrappedException}

Inner Exception: Error HRESULT E_FAIL has been returned from a call to a COM component.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.UIElement_Measure(UIElement element, Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

Which triggers the same error message I was getting before:

Line: 58
Error: Unhandled Error in Silverlight Application
Code: 2531    
Category: ParserError       
Message: Failed to assign to property 'System.Windows.Controls.ContentPresenter.Content'.     
File:      
Line: 5497     
Position: 78     

Thanks,
Ravin

0
Nasko
Telerik team
answered on 06 Oct 2015, 06:40 AM
Hello Ravin,

I tried to reproduce the error for SL5 on our side but without any success. I am attaching the sample project that we used for our tests. Could you please, try to modify it in order to reproduce the error and send the project back to us?With a sample project that reproduces the issue we could be able to continue our investigation and provide you with a prompt solution or same detailed technical instructions how to resolve it.

We are looking forward to hearing from you. 

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Ravin
Top achievements
Rank 1
answered on 13 Oct 2015, 01:56 PM

Changing the code in your sample helped me replicate the issue, basically you can't set 2 or more RadMenuItem Icon properties to the same object or you get the error:

Image iconCopy = new Image()
{
    Width = 16,
    Height = 16,
    Source = new BitmapImage(new Uri("/RadContextMenuIconSL;component/Images/copy.png", UriKind.RelativeOrAbsolute))
};
 
this.GridContextMenu = new RadContextMenu();
this.GridContextMenu.Items.Add(new RadMenuItem() { Header = "Header1", Icon = iconCopy });
this.GridContextMenu.Items.Add(new RadMenuItem() { Header = "Header2", Icon = iconCopy });

Having found the error, I did a bit of research and found I could instead do something like the following to get it to work:

//Image iconCopy = new Image()
//{
//    Width = 16,
//    Height = 16,
//    Source = new BitmapImage(new Uri("/RadContextMenuIconSL;component/Images/copy.png", UriKind.RelativeOrAbsolute))
//};
 
DataTemplate iconDataTemplate = XamlReader.Load(
        <Image Source=""/RadContextMenuIconSL;component/Images/copy.png"" Width=""16"" Height=""16"" />
    </DataTemplate>") as DataTemplate;
 
this.GridContextMenu = new RadContextMenu();
this.GridContextMenu.Items.Add(new RadMenuItem() { Header = "Header1", IconTemplate = iconDataTemplate });
this.GridContextMenu.Items.Add(new RadMenuItem() { Header = "Header2", IconTemplate = iconDataTemplate });

Thanks,
Ravin

0
Nasko
Telerik team
answered on 14 Oct 2015, 08:58 AM
Hello Ravin,

I am really glad that you managed to find the reason for your issue and we are really thankful for sharing with us your solution.

If you have any additional questions or concerns please, do not hesitate to contact us.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Navigation
Asked by
Ravin
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Ravin
Top achievements
Rank 1
Share this question
or