Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Adding content to a TableCell within C#

 
 
Old 01-10-2006   #1 (permalink)
Jason Dolinger


 
 

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]


 
 

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


 
 

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]


 
 

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
 

Thread Tools


Similar Threads
Thread Forum
Adding video content to Library Vista music pictures video
Set-Content not updating file after get-content and forEach-Object PowerShell
Adding web content to the desktop Vista General
About adding content to the same file using "add-content" PowerShell
Weirdness with get-content | replace | set-content - file content is deleted!! PowerShell


Vista Forums 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 Ltd

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