1

I'm a long time WPF designer yet new to windows app development. I'm trying to bind a collection of objects onto a grid yet keep getting the error Unknown attachable member '(Grid.Row)' on element 'FrameworkElement' and Unknown attachable member '(Grid.Column)' on element 'FrameworkElement'.

Can someone please explain to me the how to set the various Grid attached properties via style?

<ItemsControl ItemsSource="{Binding}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Grid>
                <!-- Column and row definitions omitted for brevity -->
            </Grid>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="FrameworkElement">
            <Setter Property="(Grid.Row)" Value="{Binding Row}" />
            <Setter Property="(Grid.Column)" Value="{Binding Column}" />
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>
Chris Kerekes
  • 1,116
  • 8
  • 27

2 Answers2

2

Don't use a PropertyPath. All you need is a qualified Owner.Property string.

<Setter Property="Grid.Row" Value="{Binding Row}" />

Taken from PropertyPath XAML Syntax

Some style and template properties such as Setter.Property take a qualified property name that superficially resembles a PropertyPath. But this is not a true PropertyPath; instead it is a qualified owner.property string format usage that is enabled by the WPF XAML processor in combination with the type converter for DependencyProperty.

LPL
  • 16,827
  • 6
  • 51
  • 95
  • This can only be another problem. All use it so without an error (see [here](http://stackoverflow.com/q/6995844/620360) and [here](http://stackoverflow.com/q/8727545/620360)) and for me it works too. – LPL Feb 24 '13 at 21:12
  • And there are many more examples of this working between the Grid and ItemsControl in the `System.Windows.Controls` namespace. My problem is with the windows app store controls inside the `Windows.UI.Xaml.Controls` namespace. – Chris Kerekes Feb 24 '13 at 22:35
  • Sorry, I wasn't aware that this is different in metro controls. – LPL Feb 24 '13 at 23:44
  • It turns out that the parenthesis were part of the problem but not the whole picture. The metro grid attached properties didn't like being set on a `FrameworkElement`. Updating the style's target type to `ContentPresenter` fixed this. Now to figure out why my binding isn't being read... – Chris Kerekes Feb 25 '13 at 14:59
1

It turns out that there are actually 3 problems with the code I posted above.

As @LPL correctly identified Setter.Value takes a qualified property name where a PropertyPath was being used. The fix here is to drop the parentheses: <Setter Property="Grid.Row" ... /> and <Setter Property="Grid.Column" ... />.

The second issue is with the style target type. It turns out that the metro Grid attached properties can't be applied to FrameworkElement's. The solution here is to update the target type with something more specific: <Style TargetType="ContentPresenter" />.

Finally as with Silverlight, the value property of metro setters don't support bindings. Consequently even after fixing the previous two errors, the setter is actually trying to set the grid attached properties to an instance of type Binding. While not as straight forward, all the details of a solution may be found here. In summary you can use the setter to set a custom attached property, which will in turn set up any desired binding.

Community
  • 1
  • 1
Chris Kerekes
  • 1,116
  • 8
  • 27