Wpf 散点视图项自定义形状

Wpf 散点视图项自定义形状,wpf,pixelsense,scatterview,Wpf,Pixelsense,Scatterview,我有一个ScatterViewItem,其中包含一个画布 <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" Wi

我有一个ScatterViewItem,其中包含一个画布

                <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>

                <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>
我对上面的代码有点困惑,因为我理解这行代码

                <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>
item.Content = poly 

将覆盖ScatterViewItem的内容,即在我的示例中是画布,或者在另一个示例中是图像。目前,我不需要移动或缩放散射视图项,因此不需要阴影,我只想删除矩形框。

您可以通过修改散射视图项的

                <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>
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)
如果您想删除scatterview的所有视觉功能,我想您可以使用一个空模板:

                <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>
<Style TargetType="{x:Type s:ScatterViewItem}">
    <Setter Property="Template"> 
        <Setter.Value> 
          <ControlTemplate TargetType="{x:Type s:ScatterViewItem}"> 
            <ContentPresenter /> 
          </ControlTemplate> 
        </Setter.Value> 
    </Setter>
</Style>
上面的模板将所有散点视图项更改为一个空白模板,但您可以给它一个x:Key=YourStyleName,并将相关散点视图的设置为仅影响该散点视图

                <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>

请注意,如果使用Expression Blend,则可能需要添加对Microsoft.Surface.Presentation.Generic.dll的引用才能执行此操作,否则Blend可能会在编辑模板时崩溃。

您可以通过修改ScatterViewItem的

                <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>
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)
如果您想删除scatterview的所有视觉功能,我想您可以使用一个空模板:

                <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>
<Style TargetType="{x:Type s:ScatterViewItem}">
    <Setter Property="Template"> 
        <Setter.Value> 
          <ControlTemplate TargetType="{x:Type s:ScatterViewItem}"> 
            <ContentPresenter /> 
          </ControlTemplate> 
        </Setter.Value> 
    </Setter>
</Style>
上面的模板将所有散点视图项更改为一个空白模板,但您可以给它一个x:Key=YourStyleName,并将相关散点视图的设置为仅影响该散点视图

                <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>

请注意,如果使用Expression Blend,则可能需要添加对Microsoft.Surface.Presentation.Generic.dll的引用才能执行此操作,否则Blend可能会在编辑模板时崩溃。

您还可以删除阴影,使ScatterViewItem不再可见

                <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>
假设该项目是您的ScatterViewItem:

                <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>
item.ApplyTemplate();
item.Background = new SolidColorBrush(Colors.Transparent);
item.ShowsActivationEffects = false;
Microsoft.Surface.Presentation.Generic.SurfaceShadowChrome ssc;
ssc = item.Template.FindName("shadow", item) as Microsoft.Surface.Presentation.Generic.SurfaceShadowChrome;
ssc.Visibility = Visibility.Hidden;

也可以删除阴影,使ScatterViewItem不再可见

                <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>
假设该项目是您的ScatterViewItem:

                <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>
item.ApplyTemplate();
item.Background = new SolidColorBrush(Colors.Transparent);
item.ShowsActivationEffects = false;
Microsoft.Surface.Presentation.Generic.SurfaceShadowChrome ssc;
ssc = item.Template.FindName("shadow", item) as Microsoft.Surface.Presentation.Generic.SurfaceShadowChrome;
ssc.Visibility = Visibility.Hidden;

我也有类似的问题。 这是我的密码

                <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>
 <s:ScatterView>
    <s:ScatterView.Items>
        <s:ScatterViewItem Height="1721" Width="2169">                
            <Canvas >
                <Path Data="M0 2728 l0 -1012 28 26 c23 21 32 24 61 17 31 -6 40 -3 75 27 38 32 99 114 92 122 -6 5 -46 -21 -46 -30 0 -15 -56 -58 -75 -58 -29 0 -105 74 -105 102 0 12 14 37 32 55 31 32 32 34 20 78 -20 74 -17 82 29 89 22 4 44 4 49 1 13 -8 23 54 11 69 -8 10 -6 17 8 30 12 11 16 25 13 41 -4 24 -3 25 24 15 25 -10 31 -9 43 9 7 12 24 21 37 21 25 0 30 10 14 26 -5 5 -7 20 -3 32 7 29 34 25 48 -6 12 -27 20 -28 38 -1 13 18 24 20 74 18 32 -2 173 -2 314 -1 l256 2 12 113 c6 61 12 191 12 287 1 96 5 182 10 191 14 27 76 61 98 54 24 -7 29 -20 37 -103 10 -106 29 -115 65 -33 24 57 70 104 95 99 10 -1 29 -25 43 -53 37 -72 66 -79 141 -38 78 44 123 50 180 25 88 -38 122 -38 197 0 64 31 75 33 193 36 77 3 145 -1 177 -9 45 -10 61 -10 115 5 135 37 121 41 253 -81 64 -59 124 -111 133 -114 27 -10 473 0 515 12 47 12 84 47 92 86 22 99 71 155 143 159 27 2 79 17 118 34 46 21 97 35 153 41 64 7 100 18 150 44 36 19 86 37 111 41 25 4 65 17 90 29 52 26 113 39 140 30 29 -9 25 -49 -10 -89 -25 -28 -29 -38 -21 -59 5 -14 15 -28 21 -32 12 -8 3 -73 -13 -94 -16 -19 17 -43 103 -76 66 -25 80 -27 188 -23 109 4 121 6 176 36 32 18 67 32 77 32 25 0 24 12 -1 35 -13 12 -20 29 -18 44 2 21 10 27 38 32 39 6 102 40 140 75 23 21 30 22 64 13 52 -14 82 -5 94 30 8 22 18 30 45 35 37 7 73 38 63 55 -9 14 -94 40 -158 47 l-58 7 0 87 c0 48 -3 90 -7 93 -3 4 -5 35 -4 70 3 73 24 102 105 142 l50 25 -2592 0 -2592 0 0 -1012z" Stroke="Black"></Path>
....
....
  </Canvas>
        </s:ScatterViewItem>
    </s:ScatterView.Items>
</s:ScatterView>
画布上有如此多的形状,画布的大小也要高得多。
因此,当我运行应用程序时,当我重新调整ScatterViewItem的大小时,画布不会重新调整大小。以及我在ScatterViewItem之外显示的画布。

我也有类似的问题。
                <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>
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)
这是我的密码

                <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>
 <s:ScatterView>
    <s:ScatterView.Items>
        <s:ScatterViewItem Height="1721" Width="2169">                
            <Canvas >
                <Path Data="M0 2728 l0 -1012 28 26 c23 21 32 24 61 17 31 -6 40 -3 75 27 38 32 99 114 92 122 -6 5 -46 -21 -46 -30 0 -15 -56 -58 -75 -58 -29 0 -105 74 -105 102 0 12 14 37 32 55 31 32 32 34 20 78 -20 74 -17 82 29 89 22 4 44 4 49 1 13 -8 23 54 11 69 -8 10 -6 17 8 30 12 11 16 25 13 41 -4 24 -3 25 24 15 25 -10 31 -9 43 9 7 12 24 21 37 21 25 0 30 10 14 26 -5 5 -7 20 -3 32 7 29 34 25 48 -6 12 -27 20 -28 38 -1 13 18 24 20 74 18 32 -2 173 -2 314 -1 l256 2 12 113 c6 61 12 191 12 287 1 96 5 182 10 191 14 27 76 61 98 54 24 -7 29 -20 37 -103 10 -106 29 -115 65 -33 24 57 70 104 95 99 10 -1 29 -25 43 -53 37 -72 66 -79 141 -38 78 44 123 50 180 25 88 -38 122 -38 197 0 64 31 75 33 193 36 77 3 145 -1 177 -9 45 -10 61 -10 115 5 135 37 121 41 253 -81 64 -59 124 -111 133 -114 27 -10 473 0 515 12 47 12 84 47 92 86 22 99 71 155 143 159 27 2 79 17 118 34 46 21 97 35 153 41 64 7 100 18 150 44 36 19 86 37 111 41 25 4 65 17 90 29 52 26 113 39 140 30 29 -9 25 -49 -10 -89 -25 -28 -29 -38 -21 -59 5 -14 15 -28 21 -32 12 -8 3 -73 -13 -94 -16 -19 17 -43 103 -76 66 -25 80 -27 188 -23 109 4 121 6 176 36 32 18 67 32 77 32 25 0 24 12 -1 35 -13 12 -20 29 -18 44 2 21 10 27 38 32 39 6 102 40 140 75 23 21 30 22 64 13 52 -14 82 -5 94 30 8 22 18 30 45 35 37 7 73 38 63 55 -9 14 -94 40 -158 47 l-58 7 0 87 c0 48 -3 90 -7 93 -3 4 -5 35 -4 70 3 73 24 102 105 142 l50 25 -2592 0 -2592 0 0 -1012z" Stroke="Black"></Path>
....
....
  </Canvas>
        </s:ScatterViewItem>
    </s:ScatterView.Items>
</s:ScatterView>
画布上有如此多的形状,画布的大小也要高得多。
因此,当我运行应用程序时,当我重新调整ScatterViewItem的大小时,画布不会重新调整大小。还有我在ScatterViewItem外展示的画布。

谢谢你的回答,非常感谢。我花了好几个小时试图在SDS中学习拼图的例子,但却一无所获。我没有意识到使用ControlTemplate有多么简单。谢谢你的回答,非常感谢。我花了好几个小时试图在SDS中学习拼图的例子,但却一无所获。我没有意识到使用ControlTemplate是多么简单。
                <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>
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)