wpfpixelsensescatterview

ScatterViewItem Custom Shape


I have a ScatterViewItem which contains a Canvas

                <Ellipse x:Name="Outer_Ellipse" Fill="White" Width="200" Height="200"></Ellipse>
                <Ellipse Fill="Red" Canvas.Top ="15" Canvas.Left="15" Canvas.Right="15" Canvas.Bottom="15" Width="170" Height="170" ></Ellipse>

            </Canvas>
        </s:ScatterViewItem>

Id like to provide a Custom Shape so that the default rectangle shape is not show (here is a picture of my current implementation alt text.

I followed this example here link text and have consulted the Puzzle that comes with the SDK but I am unable to get it working, my ScatterViewItem is blank.

I defined a path in the SurfaceWindow.Resources

 <Path x:Key="ScatterShape" Fill="Blue">
        <Path.Data>
            <EllipseGeometry 
                RadiusX="200"
                RadiusY="200">
            </EllipseGeometry>
        </Path.Data>
    </Path>

And copied the style attributes from the link above. I created my CustomShape.cs as instructed and then created the ScatterViewItem.

System.Windows.Shapes.Path path;
path = (System.Windows.Shapes.Path)Resources["ScatterShape"];
CustomShape poly = new CustomShape(path.Data);
ScatterViewItem item = new ScatterViewItem();
item.Content = poly;
item.CanScale = false;
Binding binding = new Binding();
binding.Source = poly;
item.SetBinding(ScatterViewItem.DataContextProperty, binding);
scatter.Items.Add(item)

Im slightly confused with the above code since my understanding with the line

item.Content = poly 

would overwrite the content of the ScatterViewItem (i.e in my case the Canvas or in another case say an Image). For the time being I don't need to move or scale the ScatterView item so no shadows are neccessary I just simply want to remove the rectangular box.


Solution

  • You can achieve this by modifying the ControlTemplate for the ScatterViewItem.

    If you want to remove all the visual features of the scatterview then I guess you could get away with an empty template:

    <Style TargetType="{x:Type s:ScatterViewItem}">
        <Setter Property="Template"> 
            <Setter.Value> 
              <ControlTemplate TargetType="{x:Type s:ScatterViewItem}"> 
                <ContentPresenter /> 
              </ControlTemplate> 
            </Setter.Value> 
        </Setter>
    </Style>
    

    The above template will change all scatterview items to have a blank template, but you could give it a x:Key="YourStyleName" and set the ItemContainerStyle of the ScatterView in question to only affect that scatter view.

    Please note that if you use Expression Blend, you may need to add a reference to Microsoft.Surface.Presentation.Generic.dll to do this or Blend may crash when editing the template.