Just to give you a quick overview, just trying to create somewhat of a tile editor. So I made custom tile objects which will be represted through a contenttemplate displaying each as a rectangle. I am using a listbox as my container but I set the ItemsPanelTemplate of that container to use a grid. The problem is, setting Grid.Row or Grid.Column in my contenttemplate does nothing. I'm sure it has something to do with the fact that my grid is defined within the template but I'm not sure how.
Here is my XAML:
<Window x:Class="InvisTile.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustomControls"
Title="MainWindow" Height="200" Width="200">
<Window.Resources>
<ControlTemplate x:Key="TileTemplate" TargetType="{x:Type ListBoxItem}">
//Hard coded to grid location but only staying in 0,0
<local:Tile BorderBrush="Aqua" MouseDown="Tile_MouseDoubleClick" Grid.Row="1" Grid.Column="1">
<Rectangle Fill="Transparent" Stroke="Green"></Rectangle>
</local:Tile>
</ControlTemplate>
</Window.Resources>
<ListBox Name="lstTiles">
<ListBox.ItemContainerStyle>
<Style>
<Setter Property="Control.Template" Value="{StaticResource TileTemplate}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<local:Tile></local:Tile>
</ListBox>