Posted on 02/10/2020 05:23:13
Hi Lars,
I've tried code sample for button ribbon button add-in and I had no problems with that, Lazy onli initializes value at the time first call occured in the runtime, that might be your problem?
you can try my example, may be it will clarify something:
[AddInTarget(RibbonBarAddInTarget.eCom.OrderList)]
public class MyAddin : RibbonBarAddIn
{
///
/// Initializes a new instance of the MyAddin class.
///
public MyAddin(RibbonBar ribbon)
: base(ribbon)
{
}
public override void Load()
{
// To learn more about RibbonBarAddIns, check out: http://developer.dynamicweb-cms.com/documentation/for-developers/cms-extensibility/ribbon-bar.aspx
RibbonBarGroup group = base.CreateDefaultContainer();
RibbonBarButton button = new RibbonBarButton();
group.Name = "My group";
group.AddItem(button);
// Access the DataContext which is a Order collection for this AddIn.
var orders = base.Ribbon.DataContext.DataSource as Lazy>;
double ordersTotal = 0.0;
if (orders != null && orders.Value != null)
{
foreach (var order in orders.Value) {
ordersTotal += order.TotalPrice;
}
/// process orders.Value
}
button.Text = $"Orders total {Services.Currencies.Format(Context.Currency, ordersTotal)}";
button.DoTranslate = false;
button.Title = "some hover text";
button.Icon = KnownIcon.Money;
// Alternatively, specify your own Image path:
// button.ImagePath = "/Admin/SomeImage.png";
button.Size = Icon.Size.Large;
button.EnableServerClick = true;
button.Click += button_Click;
}
void button_Click(object sender, EventArgs e)
{
// Handle click here
}
}
if you will still have some problems or questions, let me know I will glad to help.
BR, Viktor.