![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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> |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| 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? | Vista file management | |||
| How to bind to AD without displaying the Distinguished Name | PowerShell | |||
| in a bind | Vista mail | |||
| Bind to LDAP Directory | PowerShell | |||