Excel ribbon doesn't show up with excel-dna - excel-dna

Tried to create a ribbon with excel-dna and C#. The ribbon is not displayed in excel when the add-in is loaded.
dna file:
<DnaLibrary Name="falcon" RuntimeVersion="v4.0">
<ExternalLibrary Path="bin/Debug/falcon.dll" />
<!--<Reference AssemblyPath="System.Windows.Forms.dll" />-->
<CustomUI>
<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='OnLoad'>
<ribbon>
<tabs>
<tab id='CustomTab' label='My Tab' insertAfterMso='View'>
<group id='SampleGroup' label='My Group'>
<button id='LoginCmd' onAction='OnLogonPressed' label='logon' />
</group >
</tab>
</tabs>
</ribbon>
</customUI>
</CustomUI>
</DnaLibrary>
cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using System.Runtime.InteropServices;
using ExcelDna.Integration.CustomUI;
namespace MyLibrary
{
[ComVisible(true)]
public class Ribbon : ExcelRibbon
{
private IRibbonUI ribbon = null;
public void OnLogonPressed(IRibbonControl control)
{
if (ribbon != null)
{
ribbon.InvalidateControl(control.Id);
}
}
public void OnLoad(IRibbonUI ribbon)
{
this.ribbon = ribbon;
}
}
}
I use Visual Studio Community Edition and the code compiles with .NET 4.6. I load the add-in by clicking directly on the xll file or by loading it in a new excel file. In excel the add-in tab is enabled and the macro security is on the lowest level. Furthermore I enabled under Settings > Advanced the option to show all errors for UI add-in's. I use excel 2010.
When I open excel the ribbon is not shown neither a error message. Anyone any suggestions?

I had similar problem, but it works after I made assembly ComVisible as well:
[<assembly: ComVisible(true)>]

Related

How can I create an spinning picker in Xamarin?

I am trying to get my picker to be an wheel/spinning type.
My Current Picker:
<Picker x:Name="AmountPicker" />
AmountPicker.ItemsSource = new List<string>() { "1", "2", "3","4","5","6","7","8" };
My Picker
You have a couple of options.
1. Use Custom Renderers which enables you to achieve the wheel/spinning type. There is a similar thread you could refer to: Apply styles on Picker items in Xamarin Forms.
1.1 Create the Custom Picker Control in Shared Project:
public class MyPicker : Picker
{
}
1.2 Creating the Custom Renderer on Android & iOS:
Android:
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(MyPicker), typeof(MyPickerRenderer))]
namespace App35.Droid
{
class MyPickerRenderer : PickerRenderer
{
public MyPickerRenderer(Context context) : base(context)
{
}
}
}
iOS:
[assembly: ExportRenderer(typeof(MyPicker), typeof(MyPickerRenderer))]
namespace App35.iOS
{
class MyPickerRenderer : PickerRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
base.OnElementChanged(e);
}
}
}
1.3 Consume it in XAML:
<local:MyPicker ItemsSource="{Binding MyListProperty}" ></local:MyPicker>
Output:
2. Use Xamarin.SfPicker. Firstly, install the package and then set SfPicker control namespace as xmlns:syncfusion="clr- namespace:Syncfusion.SfPicker.XForms;assembly=Syncfusion.SfPicker.XForms in XAML Content page. So you can consume it in XAML like below.For more you can refer to Getting Started with Xamarin Picker (SfPicker)
<syncfusion:SfPicker x:Name="picker" HeaderText="Choose Value" />
3. Use Wheel Picker for Xamarin Samples package, you can refer to Wheel Picker for Xamarin Samples for more details.

is there any way to set Source for Image From .standard Class Library in UWP

I have create Xamarin Native App only create UI Part platform specfic and shared code(Model,ViewModel) using .net stadard class Library.
In UWP Project I set Source Path Like this
Source="pack://application:,,,/MyClassLibraryName;Component/Assets/AppLogo.png"
It does not work for me!
I have create Xamarin Native App only create UI Part platform specfic and shared code(Model,ViewModel) using .net stadard class Library
For this scenario, you could refer this document that make ImageResourceExtension to load the Embedded image from .net stadard class Library.
We need add the following code to .net stadard class Library.
[Preserve(AllMembers = true)]
[ContentProperty(nameof(Source))]
public class ImageExtension : IMarkupExtension
{
public string Source { get; set; }
public object ProvideValue(IServiceProvider serviceProvider)
{
if (Source == null)
return null;
// Do your translation lookup here, using whatever method you require
var imageSource = ImageSource.FromResource(Source, typeof(ImageExtension).GetTypeInfo().Assembly);
return imageSource;
}
}
Then add image file to .net standard class library and edit the Build Action to Embedded
Usage
ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mySource="clr-namespace:ImageLib;assembly=ImageLib"
x:Class="WorkingWithImages.EmbeddedImagesXaml">
<StackLayout Margin="20,35,20,20">
<Image Source="{mySource:Image ImageLib.logo.jpg}" />
</StackLayout>
/ContentPage>
Please note: Image path is classlibname.imagename.jpg
Update
You could use uwp uri scheme to add the image path to imgage control, for example
<ImageBrush ImageSource="ms-appx:///Image/AppLogoicon.png" Stretch="UniformToFill" x:Name="Image" />

Xamarin.Forms ViewCell / Visual Studio 2019 - "Partial declarations of 'someType' must not specify different base classes"

In my Xamarin.Forms project I am attempting to create a reusable ViewCell. I can't figure out, though, why when I simply create a ViewCell XAML and CS file using the VS-supplied template, it will not compile due to the following error:
"Partial declarations of 'DateViewCell' must not specify different base classes"
This error pops the second I create the file (as you'll see in the code below, I haven't added any code yet and this is all boilerplate) and I have a fully functional Xamarin.Forms project that compiles with no issues if I remove the extension.
DateViewCell.xaml:
<?xml version="1.0" encoding="UTF-8"?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="HelloWorld.Extensions.DateViewCell">
<ViewCell.View>
<StackLayout>
<Label Text="Hello Xamarin.Forms!" />
</StackLayout>
</ViewCell.View>
</ViewCell>
DateViewCell.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace HelloWorld.Extensions
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DateViewCell : ViewCell
{
public DateViewCell()
{
InitializeComponent();
}
}
}
DateViewCell.xaml.g.cs:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
[assembly: global::Xamarin.Forms.Xaml.XamlResourceIdAttribute("HelloWorld.Extensions.DateViewCell.xaml", "Extensions/DateViewCell.xaml", typeof(global::HelloWorld.Extensions.DateViewCell))]
namespace HelloWorld.Extensions {
[global::Xamarin.Forms.Xaml.XamlFilePathAttribute("Extensions\\DateViewCell.xaml")]
public partial class DateViewCell : global::Xamarin.Forms.ViewCell {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "2.0.0.0")]
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(DateViewCell));
}
}
}
Sort of at a dead end here. I tried creating this "DateViewCell" extension manually and I get the same error that I did when I let VS create the file for me. I'm starting to wonder if this is a bug in Xamarin.
Anyone have any suggestions? The SO articles I could find that referenced this particular error didn't really apply and I'm out of ideas on better ways to search this... Thanks everybody.

my activity_main.axml in visual studio 2017 xamarin android app don't have any layout design showed

Hello and good day developers, I am here again to ask you some
question-related to my new build project in visual studio 2017 xamarin
the android app.used blank app..the issue is I can't see my layout design,
also when I drag and drop a button, textbox etc, but when I click the
centre of the white background there is a rectangular blueprint show
or blue border...
Note: this is a built-in code.
// activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
// MainActivity.cs
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Runtime;
using Android.Widget;
namespace MhylesOrdering
{
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
}
}
}
// ScreeenShot
Now I added new layout which is the layout1.axml but the issue is
still there

Icon Handler shows black icons

I am using Sharpshell to change my pdf and xlsx icons. Most of the times it works fine, but sometimes it shows black icons. Refreshing or restarting explorer has no effect on it.
Moreover, it works fine in certain Icon Views - for example in Details, Content it works fine, but not in Medium Icons or Tiles. Also, the icons work fine in the Server Manager tool.
There is one more thing - if I change the name of the file that has got the black icon, the correct icon immediately appears.
This is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using SharpShell.SharpIconHandler;
using SharpShell.Attributes;
using SharpShell.Configuration;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using SharpShell.Diagnostics;
using SharpShell.Interop;
namespace IconHandlerTry2
{
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".pdf", ".xlsx")]
public class Class1 : SharpIconHandler
{
/// <summary>
/// Gets the icon.
/// </summary>
/// <param name="smallIcon">if set to <c>true</c> provide a small icon.</param>
/// <param name="iconSize">Size of the icon.</param>
/// <returns>
/// The icon for the file.
/// </returns>
protected override Icon GetIcon(bool smallIcon, uint iconSize)
{
string prefix = "C:\\Windows\\IconsForYou\\";
string filename = SelectedItemPath;
string iconFileName;
string[] splits = filename.Split('.');
string extension = splits[splits.Length - 1];
if (extension == "pdf")
iconFileName = prefix + "pdfDefault.ico";
else if (extension == "xlsx")
iconFileName = prefix + "xlsxDefault.ico";
else
iconFileName = prefix + "default.ico";
Icon icon = new Icon(iconFileName);
// Return the icon with the correct size. Use the SharpIconHandler 'GetIconSpecificSize'
// function to extract the icon of the required size.
return GetIconSpecificSize(icon, new Size((int)iconSize, (int)iconSize));
}
}
}
This is the simpler version. I will be working on hundreds of icons. Does anybody have any suggestion?
EDIT: I now see that the icons are assigned randomly. Whenever I clear the icon cache, some random icons are displayed. Sometimes there is nothing, so it becomes either full black or white. Same thing is happening in the Server Manager Tool. Please help!

Resources