Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Adding content to a TableCell within C#

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
Jason Dolinger
Guest


 

Adding content to a TableCell within C#

Does anyone know how to add content to a TableCell from C#? I'd
basically like to recreate the following XAML code:

<Table CellSpacing="6">
<TableRowGroup>
<TableRow>
<TableCell>
<Paragraph>Chocolate</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Yummy</Paragraph>
</TableCell>
<TableCell>
<Paragraph>Widespread</Paragraph>
</TableCell>
</TableRow>




etc...

XAML doesn't really support building this up dynamically... I need to
create TableCells based on a collection of data. Forgetting the
looping, just building up a single branch of objects looks like this:

// create the table
Table tab = new Table();

// create a row group
TableRowGroup rowGroup = new TableRowGroup();
tab.RowGroups.Add(rowGroup);

// create a row
TableRow row = new TableRow();
rowGroup.Rows.Add(row);

// create a cell
TableCell cell = new TableCell();
row.Cells.Add(cell);


All, well and good, but how do I add text to that cell? I can create a
Paragraph class, but how do you add it to teh cell?


On a larger note, is there some way to take a snippet of XAML code and
see the C# code that actually runs when that XAML is executed? I run
into a lot of blockages when I can't figure out how to do something that
C# that I have XAML syntax for and vice-versa. XAML doesn't really
cut it for building lists and tables, etc. (perhaps if databinding
worked better?)

Thanks,
Jason








My System SpecsSystem Spec
Old 01-10-2006   #2 (permalink)
Ifeanyi Echeruo [MSFT]
Guest


 

Re: Adding content to a TableCell within C#

With Dec CTP

Cell cell = new Cell();
Paragraph para = new Paragraph();
cell.Blocks.Add(para);

We had implemented data binding a while back on table rows but it was too
limited and essentially turned typographic tables into glorified listboxes.
Without clearer scenarios or cleaner design we yanked it.

--Ifeanyi Echeruo [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.

"Jason Dolinger" <jdolinger@lab49.com> wrote in message
news:eZh%23U1NBGHA.2912@tk2msftngp13.phx.gbl...
> Does anyone know how to add content to a TableCell from C#? I'd basically
> like to recreate the following XAML code:
>
> <Table CellSpacing="6">
> <TableRowGroup>
> <TableRow>
> <TableCell>
> <Paragraph>Chocolate</Paragraph>
> </TableCell>
> <TableCell>
> <Paragraph>Yummy</Paragraph>
> </TableCell>
> <TableCell>
> <Paragraph>Widespread</Paragraph>
> </TableCell>
> </TableRow>
>
>
>
>
> etc...
>
> XAML doesn't really support building this up dynamically... I need to
> create TableCells based on a collection of data. Forgetting the looping,
> just building up a single branch of objects looks like this:
>
> // create the table
> Table tab = new Table();
>
> // create a row group
> TableRowGroup rowGroup = new TableRowGroup();
> tab.RowGroups.Add(rowGroup);
>
> // create a row
> TableRow row = new TableRow();
> rowGroup.Rows.Add(row);
>
> // create a cell
> TableCell cell = new TableCell();
> row.Cells.Add(cell);
>
>
> All, well and good, but how do I add text to that cell? I can create a
> Paragraph class, but how do you add it to teh cell?
>
>
> On a larger note, is there some way to take a snippet of XAML code and see
> the C# code that actually runs when that XAML is executed? I run into a
> lot of blockages when I can't figure out how to do something that C# that
> I have XAML syntax for and vice-versa. XAML doesn't really cut it for
> building lists and tables, etc. (perhaps if databinding worked better?)
>
> Thanks,
> Jason
>
>
>
>
>
>
>


My System SpecsSystem Spec
Old 01-10-2006   #3 (permalink)
Jason Dolinger
Guest


 

Re: Adding content to a TableCell within C#

Ok cool. Is there DataBinding available on TableCell? ie. if I want
to bind the content of a particular cell to a given cell in a DataTable,
can I set that up with a Binding object?

Thanks!
Jason

Ifeanyi Echeruo [MSFT] wrote:
> With Dec CTP
>
> Cell cell = new Cell();
> Paragraph para = new Paragraph();
> cell.Blocks.Add(para);
>
> We had implemented data binding a while back on table rows but it was too
> limited and essentially turned typographic tables into glorified listboxes.
> Without clearer scenarios or cleaner design we yanked it.
>
> --Ifeanyi Echeruo [MSFT]
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Jason Dolinger" <jdolinger@lab49.com> wrote in message
> news:eZh%23U1NBGHA.2912@tk2msftngp13.phx.gbl...
>
>>Does anyone know how to add content to a TableCell from C#? I'd basically
>>like to recreate the following XAML code:
>>
>><Table CellSpacing="6">
>><TableRowGroup>
>><TableRow>
>><TableCell>
>><Paragraph>Chocolate</Paragraph>
>></TableCell>
>><TableCell>
>><Paragraph>Yummy</Paragraph>
>></TableCell>
>><TableCell>
>><Paragraph>Widespread</Paragraph>
>></TableCell>
>></TableRow>
>>
>>
>>
>>
>>etc...
>>
>>XAML doesn't really support building this up dynamically... I need to
>>create TableCells based on a collection of data. Forgetting the looping,
>>just building up a single branch of objects looks like this:
>>
>>// create the table
>>Table tab = new Table();
>>
>>// create a row group
>>TableRowGroup rowGroup = new TableRowGroup();
>>tab.RowGroups.Add(rowGroup);
>>
>>// create a row
>>TableRow row = new TableRow();
>>rowGroup.Rows.Add(row);
>>
>>// create a cell
>>TableCell cell = new TableCell();
>>row.Cells.Add(cell);
>>
>>
>>All, well and good, but how do I add text to that cell? I can create a
>>Paragraph class, but how do you add it to teh cell?
>>
>>
>>On a larger note, is there some way to take a snippet of XAML code and see
>>the C# code that actually runs when that XAML is executed? I run into a
>>lot of blockages when I can't figure out how to do something that C# that
>>I have XAML syntax for and vice-versa. XAML doesn't really cut it for
>>building lists and tables, etc. (perhaps if databinding worked better?)
>>
>>Thanks,
>>Jason
>>
>>
>>
>>
>>
>>
>>

My System SpecsSystem Spec
Old 01-31-2006   #4 (permalink)
Ifeanyi Echeruo [MSFT]
Guest


 

Re: Adding content to a TableCell within C#

Unfortunately there is no builtin data binding for complex content including
the contents of TableCells
But you do have some options

1) Place a databound TextBlock in your TableCell

<TableCell><InlineUIContainer><TextBlock Text="{Binding ...}" /> ...

Note: You lose the ability to wrap the databound text

2) Inherit from Run, implement a bindable dp and use that in your table cell

Markup ...
<TableCell><Paragraph><custom:MyRun Text="{Binding ...}" /> ...

Codebehind ...

public class MyRun : Run {
public static readonly DependencyProperty TextProperty; //declare bindable
dp

static MyRun() {
//register bindable dp
FrameworkPropertyMetadata textPropertyMetadata = new
FrameworkPropertyMetadata(null,
FrameworPropertyMetadataOptions.AffectsRender, new
PropertyChangedCallback(MyRun.OnTextPropertyChanged));
TextProperty = DependencyProperty.Register("Text", typeof(string),
typeof(MyRun), textPropertyMetadata);
}

//new convenience clr accessor (new keyword required because Text property
is not virtual on base class)
public new string Text {
get { return (string)base.GetValue(MyRun.TextProperty); }
set { base.SetValue(MyRun.TextProperty, value); }
}

//this is where the magic happens, any changes to MyRun.TextProperty are
redirected to Run.Text
private static void OnTextPropertyChanged(DependecyObject element,
DependencyPropertyChangedEventArgs e) {
//we can try to do smart things like skip the below if the strings are
the same
Run run = (Run)element;
run.Text = (string)e.NewValue;
}
}

--Ifeanyi Echeruo [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.

"Jason Dolinger" <jdolinger@lab49.com> wrote in message
news:u4ifhVkBGHA.2704@TK2MSFTNGP15.phx.gbl...
> Ok cool. Is there DataBinding available on TableCell? ie. if I want to
> bind the content of a particular cell to a given cell in a DataTable, can
> I set that up with a Binding object?
>
> Thanks!
> Jason
>
> Ifeanyi Echeruo [MSFT] wrote:
>> With Dec CTP
>>
>> Cell cell = new Cell();
>> Paragraph para = new Paragraph();
>> cell.Blocks.Add(para);
>>
>> We had implemented data binding a while back on table rows but it was too
>> limited and essentially turned typographic tables into glorified
>> listboxes. Without clearer scenarios or cleaner design we yanked it.
>>
>> --Ifeanyi Echeruo [MSFT]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> "Jason Dolinger" <jdolinger@lab49.com> wrote in message
>> news:eZh%23U1NBGHA.2912@tk2msftngp13.phx.gbl...
>>
>>>Does anyone know how to add content to a TableCell from C#? I'd
>>>basically like to recreate the following XAML code:
>>>
>>><Table CellSpacing="6">
>>><TableRowGroup>
>>><TableRow>
>>><TableCell>
>>><Paragraph>Chocolate</Paragraph>
>>></TableCell>
>>><TableCell>
>>><Paragraph>Yummy</Paragraph>
>>></TableCell>
>>><TableCell>
>>><Paragraph>Widespread</Paragraph>
>>></TableCell>
>>></TableRow>
>>>
>>>
>>>etc...
>>>
>>>XAML doesn't really support building this up dynamically... I need to
>>>create TableCells based on a collection of data. Forgetting the looping,
>>>just building up a single branch of objects looks like this:
>>>
>>>// create the table
>>>Table tab = new Table();
>>>
>>>// create a row group
>>>TableRowGroup rowGroup = new TableRowGroup();
>>>tab.RowGroups.Add(rowGroup);
>>>
>>>// create a row
>>>TableRow row = new TableRow();
>>>rowGroup.Rows.Add(row);
>>>
>>>// create a cell
>>>TableCell cell = new TableCell();
>>>row.Cells.Add(cell);
>>>
>>>
>>>All, well and good, but how do I add text to that cell? I can create a
>>>Paragraph class, but how do you add it to teh cell?
>>>
>>>
>>>On a larger note, is there some way to take a snippet of XAML code and
>>>see the C# code that actually runs when that XAML is executed? I run
>>>into a lot of blockages when I can't figure out how to do something that
>>>C# that I have XAML syntax for and vice-versa. XAML doesn't really cut
>>>it for building lists and tables, etc. (perhaps if databinding worked
>>>better?)
>>>
>>>Thanks,
>>>Jason



My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding video content to Library BeretDude Vista music pictures video 0 07-05-2008 06:54 AM
Set-Content not updating file after get-content and forEach-Object Tolli PowerShell 1 06-14-2007 09:01 PM
Adding web content to the desktop MurfQ Vista General 5 06-05-2007 02:28 PM
About adding content to the same file using "add-content" =?Utf-8?B?ZGFuY2UyZGll?= PowerShell 3 08-14-2006 11:59 AM
Weirdness with get-content | replace | set-content - file content is deleted!! Andrew Watt [MVP] PowerShell 4 05-23-2006 05:59 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51