public MainWindow()
{
InitializeComponent();
GrapeCity.Xaml.SpreadSheet.UI.DrawingObjectManager.SetDrawingObjectProvider(this.gcSpreadSheet1, new MyObjectProvider());
this.gcSpreadSheet1.Sheets[0].ConditionalFormats.AddRule(new MyDrawingCell(2, 2));
}
public class MyObjectProvider : GrapeCity.Xaml.SpreadSheet.UI.IDrawingObjectProvider
{
#region IDrawingObjectProvider Members
public GrapeCity.Xaml.SpreadSheet.Data.DrawingObject[] GetDrawingObjects(GrapeCity.Xaml.SpreadSheet.Data.Worksheet sheet, int row, int column, int rowCount, int columnCount)
{
List<GrapeCity.Xaml.SpreadSheet.Data.DrawingObject> list = new List<GrapeCity.Xaml.SpreadSheet.Data.DrawingObject>();
if (sheet.ConditionalFormats != null)
{
for (int i = 0; i < sheet.ConditionalFormats.RuleCount; i++)
{
MyDrawingCell rule = sheet.ConditionalFormats[i] as MyDrawingCell;
if (rule != null)
{
GrapeCity.Xaml.SpreadSheet.Data.DrawingObject darwingObject = rule.Evaluate(sheet, row, column, null) as GrapeCity.Xaml.SpreadSheet.Data.DrawingObject;
if (darwingObject != null)
{
list.Add(darwingObject);
}
}
}
}
return list.ToArray();
}
#endregion
}
public class MyDrawingCell : GrapeCity.Xaml.SpreadSheet.Data.FormattingRuleBase
{
public MyDrawingCell()
: this(-1, -1)
{
}
public MyDrawingCell(int row, int column)
: base(null)
{
this.Row = row;
this.Column = column;
}
public int Row
{
get;
set;
}
public int Column
{
get;
set;
}
protected override GrapeCity.Xaml.SpreadSheet.Data.ConditionBase CreateCondition()
{
return null;
}
public override object Evaluate(GrapeCity.Xaml.SpreadSheet.Data.ICalcEvaluator evaluator, int baseRow, int baseColumn, GrapeCity.Xaml.SpreadSheet.Data.IActualValue actual)
{
if (this.Row == baseRow && this.Column == baseColumn)
return new MyButtonCell(baseRow, baseColumn);
else
return null;
}
}
internal class MyButtonCell : GrapeCity.Xaml.SpreadSheet.UI.CustomDrawingObject
{
private Button button;
public override FrameworkElement RootElement
{
get
{
if (this.button == null)
{
this.button = new Button(); // HyperlinkButton(); //
this.button.Click += new RoutedEventHandler(this.button_Click);
this.button.Content = "Click me!";
}
return this.button;
}
}
public MyButtonCell(int row, int column)
: base(row, column)
{
base.ShowDrawingObjectOnly = true;
}
private void button_Click(object sender, RoutedEventArgs e)
{
GrapeCity.Xaml.SpreadSheet.UI.SpreadView sv = GetSpreadView(this.RootElement);
MessageBox.Show("Click " + sv.ActiveSheet.GetValue(this.AnchorRow, this.AnchorColumn));
}
private GrapeCity.Xaml.SpreadSheet.UI.SpreadView GetSpreadView(DependencyObject e)
{
var t = e;
while (t != null)
{
t = VisualTreeHelper.GetParent(t);
if (t is GrapeCity.Xaml.SpreadSheet.UI.SpreadView)
{
return t as GrapeCity.Xaml.SpreadSheet.UI.SpreadView;
}
}
return null;
}
}
Public Sub New()
InitializeComponent()
GrapeCity.Xaml.SpreadSheet.UI.DrawingObjectManager.SetDrawingObjectProvider(Me.GcSpreadSheet1, New MyObjectProvider())
Me.GcSpreadSheet1.Sheets(0).ConditionalFormats.AddRule(New MyDrawingCell(2, 2))
End Sub
Public Class MyObjectProvider
Implements GrapeCity.Xaml.SpreadSheet.UI.IDrawingObjectProvider
#Region "IDrawingObjectProvider Members"
Public Function GetDrawingObjects(sheet As GrapeCity.Xaml.SpreadSheet.Data.Worksheet, row As Integer, column As Integer, rowCount As Integer, columnCount As Integer) As GrapeCity.Xaml.SpreadSheet.Data.DrawingObject() Implements GrapeCity.Xaml.SpreadSheet.UI.IDrawingObjectProvider.GetDrawingObjects
Dim list As New List(Of GrapeCity.Xaml.SpreadSheet.Data.DrawingObject)()
If sheet.ConditionalFormats IsNot Nothing Then
For i As Integer = 0 To sheet.ConditionalFormats.RuleCount - 1
Dim rule As MyDrawingCell = TryCast(sheet.ConditionalFormats(i), MyDrawingCell)
If rule IsNot Nothing Then
Dim darwingObject As GrapeCity.Xaml.SpreadSheet.Data.DrawingObject = TryCast(rule.Evaluate(sheet, row, column, Nothing), GrapeCity.Xaml.SpreadSheet.Data.DrawingObject)
If darwingObject IsNot Nothing Then
list.Add(darwingObject)
End If
End If
Next
End If
Return list.ToArray()
End Function
#End Region
End Class
Public Class MyDrawingCell
Inherits GrapeCity.Xaml.SpreadSheet.Data.FormattingRuleBase
Public Sub New()
Me.New(-1, -1)
End Sub
Public Sub New(row As Integer, column As Integer)
MyBase.New(Nothing)
Me.Row = row
Me.Column = column
End Sub
Public Property Row() As Integer
Get
Return m_Row
End Get
Set(value As Integer)
m_Row = Value
End Set
End Property
Private m_Row As Integer
Public Property Column() As Integer
Get
Return m_Column
End Get
Set(value As Integer)
m_Column = Value
End Set
End Property
Private m_Column As Integer
Protected Overrides Function CreateCondition() As GrapeCity.Xaml.SpreadSheet.Data.ConditionBase
Return Nothing
End Function
Public Overrides Function Evaluate(evaluator As GrapeCity.Xaml.SpreadSheet.Data.ICalcEvaluator, baseRow As Integer, baseColumn As Integer, actual As GrapeCity.Xaml.SpreadSheet.Data.IActualValue) As Object
If Me.Row = baseRow AndAlso Me.Column = baseColumn Then
Return New MyButtonCell(baseRow, baseColumn)
Else
Return Nothing
End If
End Function
End Class
Friend Class MyButtonCell
Inherits GrapeCity.Xaml.SpreadSheet.UI.CustomDrawingObject
Private button As Button
Public Overrides ReadOnly Property RootElement() As FrameworkElement
Get
If Me.button Is Nothing Then
Me.button = New Button()
' HyperlinkButton(); //
AddHandler button.Click, AddressOf button_Click
Me.button.Content = "Click me!"
End If
Return Me.button
End Get
End Property
Public Sub New(row As Integer, column As Integer)
MyBase.New(row, column)
MyBase.ShowDrawingObjectOnly = True
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs)
Dim sv As GrapeCity.Xaml.SpreadSheet.UI.SpreadView = GetSpreadView(Me.RootElement)
MessageBox.Show("Click " + sv.ActiveSheet.GetValue(Me.AnchorRow, Me.AnchorColumn))
End Sub
Private Function GetSpreadView(e As DependencyObject) As GrapeCity.Xaml.SpreadSheet.UI.SpreadView
Dim t = e
While t IsNot Nothing
t = VisualTreeHelper.GetParent(t)
If TypeOf t Is GrapeCity.Xaml.SpreadSheet.UI.SpreadView Then
Return TryCast(t, GrapeCity.Xaml.SpreadSheet.UI.SpreadView)
End If
End While
Return Nothing
End Function
End Class