Search code examples
wpfscatterview

Getting a "Style" attribute to work with a DataTemplate in WPF


This is a question relating to Microsoft Surface development, but I think it's more of a general WPF question as well.

How would I translate the following code, which I've found in an example:

<s:ScatterView>
    <s:ScatterViewItem Style="{DynamicResource FlippingScatterViewItemStyle}">
        // etc.
    </s:ScatterViewItem>
</s:ScatterView>

to work with data binding:

<s:ScatterView>
    <s:ScatterView.ItemTemplate>
        <DataTemplate>
            // etc.
        </DataTemplate>
    </s:ScatterView.ItemTemplate>
</s:ScatterView>

I'm not sure how to "attach" the Style declaration in the original code.

Apologies if my terminology is not correct, as I am a WPF newbie.


Solution

  • I'm not familiar with the ScatterView control but if it derives from ItemsControl which the ItemTemplate property suggests, then there should be an ItemContainerStyle property as well. The ItemContainerStyle is a style that is applied to the item itself.

    <s:ScatterView ItemContainerStyle="{DynamicResource FlippingScatterViewItemStyle}">
        <s:ScatterView.ItemTemplate>
            <DataTemplate>
                // etc.
            </DataTemplate>
        </s:ScatterView.ItemTemplate>
    </s:ScatterView>