Mixing Spreadsheets and WPF - part 2

by clearoffice 20. July 2010 19:28

As noted a previous post, Clear Office provides an unparalleled level of integration between spreadsheet documents and .NET/WPF: you can host spreadsheets inside WPF and host WPF elements inside a spreadsheet.
In particular, this means you can use data binding inside a spreadsheet.
For example, say you want to include host a slider and bind its value to the value of a cell. Here is the XAML code:

<Slider xmlns:UI='clr-namespace:Office.Spreadsheet.UI;assembly=Office.Spreadsheet.UI' xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
    Minimum='0' Maximum='100'
    Value='{Binding RelativeSource={RelativeSource Self}, Path=(UI:SpreadsheetElement.Worksheet)[A1].Value}'
</Slider>

The main point of interest is the path of the binding of the value: (UI:SpreadsheetElement.Worksheet)[A1].Value. This path contains three parts.
  • First: (SpreadsheetElement.Worksheet) is an attached property which gets the ambiant worksheet hosting the WPF element.
  • Second: [A1] access the cell named “A1” in this worksheet - class Worksheet exposes an indexer to access cells by name.
  • Third: Value accesses the value of the cell.

This binding is a two way binding: if you change the value of the cell, the slider’s value will be updated.

 

Conversely, if you slide the thumb of the slider, the value of the cell will be updated.


For more info, download the latest release candidate at www.clearoffice.com/rc and open the sample named  “EmbeddedObjectsSample”.

 

 

Tags:

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Clear Office

Official Clear Office blog

Page List