![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | Bind to a particular row and column of a dynamic grid? I'm new to WPF, so perhaps I'm going about this the wrong way. I'm trying to create a grid that contains a collection of objects. The number of rows and columns of this grid is dynamic; ideally those properties would be bound to a couple of properties of a custom object. The position of the objects within the grid would ideally be bound to properties of those objects themselves. A Grid allows items to be bound to particular rows/columns, but the total number of rows/columns must be static (at least, from a pure XAML perspective). The UniversalGrid allows binding to the total number of rows/columns, but items cannot be bound to particular rows/columns (they simply flow horizontally, wrapping with the number of columns). Below is the closest I can get to what I want. Am I on the right track? Can anyone point me in a new direction? I'm beginning to suspect it may require some codebehind. Thanks in advance, -Phil <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Page.Resources> <XmlDataProvider x:Key="InventoryData" XPath="Inventory"> <x:XData> <Inventory xmlns=""> <Wafer rows="3" columns="3"> <Die row="0" column="0" value="One"/> <Die row="1" column="1" value="Two"/> <Die row="2" column="2" value="Three"/> </Wafer> </Inventory> </x:XData> </XmlDataProvider> </Page.Resources> <ItemsControl> <ItemsControl.ItemsSource> <Binding Source="{StaticResource InventoryData}" XPath="Wafer/Die"/> </ItemsControl.ItemsSource> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid IsItemsHost="True"> <UniformGrid.Rows> <Binding Source="{StaticResource InventoryData}" XPath="Wafer/@rows"/> </UniformGrid.Rows> <UniformGrid.Columns> <Binding Source="{StaticResource InventoryData}" XPath="Wafer/@columns"/> </UniformGrid.Columns> </UniformGrid> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button Grid.Row="{Binding XPath=@row}" Grid.Column="{Binding XPath=@column}" Content="{Binding XPath=@value}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </Page> |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is it possible in "computer" to view files from top to bottom in 1st column then same again in next column to the right etc? | J | Vista file management | 0 | 07-17-2008 10:22 PM |
| in a bind | tony | Vista mail | 1 | 09-07-2007 09:07 PM |
| Bind to LDAP Directory | Tom G. | PowerShell | 11 | 12-27-2006 12:59 PM |
| UserControl cannot bind to its own properties? | lubomir@gmail.com | Avalon | 3 | 01-31-2006 06:59 AM |
| Grid.Row Grid.Column set programatically at runtime | craig kelly-soens www.XpectWorld.com | Avalon | 0 | 01-10-2006 03:52 PM |