![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |