mattercontrol/ControlElements/ConditionalClickWidget.cs

33 lines
823 B
C#
Raw Normal View History

using System;
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
public class ConditionalClickWidget : ClickWidget
{
private Func<bool> enabledCallback;
2015-04-08 15:20:10 -07:00
public ConditionalClickWidget(Func<bool> enabledCallback)
{
this.enabledCallback = enabledCallback;
}
2015-04-08 15:20:10 -07:00
// The ConditionalClickWidget provides a mechanism that allows the Enable property to be bound
// to a Delegate that resolves the value. This is a readonly value supplied via the constructor
// and should not be assigned after construction
public override bool Enabled
{
get
{
return this.enabledCallback();
}
2015-04-08 15:20:10 -07:00
set
{
Console.WriteLine("Attempted to set readonly Enabled property on ConditionalClickWidget");
#if DEBUG
2015-04-08 15:20:10 -07:00
throw new InvalidOperationException("Cannot set Enabled on ConditionalClickWidget");
#endif
2015-04-08 15:20:10 -07:00
}
}
}
}