2

I've a project where I swapped the ItemsPanelTemplate from using a StackPanel thus

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel IsItemsHost="True" Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

to using a Canvas thus

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <Canvas IsItemsHost="True" Width="Auto" Height="Auto"/>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

I'm doing this so that I can lay out the items by their start times on a timeline rather than stacked up against each other. But then I was stuck as to how to set the Canvas.Left property for each item in the ItemsControl. The obvious place (I thought) was in the Grid I use in the ItemTemplate's DataTemplate, i.e. somewhere in here:

<ItemsControl.ItemTemplate>
    <DataTemplate>
        <Grid HorizontalAlignment="Left" VerticalAlignment="Center" Height="10">
            <eventBlockVisualization:FGEventUC/>
        </Grid>
    </DataTemplate>
</ItemsControl.ItemTemplate>

But this part of the XAML has no reference to the hosting Canvas. Luckily there is a very similar question in which atsjoo asks "Setting Canvas properties in an ItemsControl DataTemplate" and Arcturus answers explaining the role and use of the ItemContainerStyle (and LiamV provides a similar answer here), which in my case results in

<ItemsControl.ItemContainerStyle>
    <Style TargetType="ContentPresenter">
        <Setter Property="Canvas.Left" Value="{Binding MinutesFromStartOfLogs}"/>
    </Style>
</ItemsControl.ItemContainerStyle>

This is all fine editing the XAML by hand but ideally I would like to manipulate these styles and bindings in Expression Blend 4 or Blend for Visual Studio 2012. If I select the ItemsControl in Blend's 'Objects and Timeline' panel and then go to the menu 'Objects -> Edit Additional Styles -> Edit Generated Item Container (ItemContainerStyle)' I do end up able to edit the ItemContainerStyle but I cannot see where Blend exposes the Canvas.Left property that is set in my XAML. Where is it? Is this 'Blendable'?

Community
  • 1
  • 1
dumbledad
  • 16,305
  • 23
  • 120
  • 273

1 Answers1

0

As far as I know this is not possible. Attached properties are not shown in Blend because there are just too many. When an element is placed directly into a canvas left and top properties are displayed, but it would be impossible to have all attached properties available. For example, you could set the Canvas.Left property if the element you set the property on is not inside a canvas.

The only way to set an attached property is to do it by hand in Xaml.

Sorskoot
  • 10,190
  • 6
  • 55
  • 98
  • What a shame this is the answer. I imagined that the XAML could be parsed to see which attached properties are available. But I think you are right. Thanks Sorskoot. – dumbledad Jan 30 '13 at 21:33