![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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) |
| | 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) |
| | 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) |
| | 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 | |
| |
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 | |||