ScatterView和ViewBox未按预期工作

时间:2010-10-27 08:23:38

标签: c# .net wpf wpf-controls pixelsense

我定义了以下布局:

<Grid Name="RootGrid" Background="{StaticResource WindowBackground}" >
        <s:ScatterView Name="RootScatter">
            <Viewbox>
                <s:LibraryContainer Name="RootContainer" Grid.Row="0" ViewingMode="Bar">
                    <s:LibraryContainer.BarView>
                        <s:BarView Rows="2" NormalizedTransitionSize="2.5,0.8" ItemTemplate="{StaticResource ContainerItemTemplate}">
                        </s:BarView>
                    </s:LibraryContainer.BarView>
                    <s:LibraryContainer.StackView>
                        <s:StackView NormalizedTransitionSize="1,1" ItemTemplate="{StaticResource ContainerItemTemplate}">
                        </s:StackView>
                    </s:LibraryContainer.StackView>
                </s:LibraryContainer>
            </Viewbox>
        </s:ScatterView>
        <s:ScatterView Name="ClassScatter"></s:ScatterView>
    </Grid>
</s:SurfaceWindow>

现在我将动态Item添加到第二个ScatterView:

public void expand(SurfaceWindow1 surfaceWindow)
        {
            Logging.Logger.getInstance().log("Expand class " + name);

            if (!isExpanded())
            {
                Viewbox vb = new Viewbox();
                SurfaceTextBox txt = new SurfaceTextBox();
                txt.Text = this.name + "\nLOC: " + this.getLoc() + "\nFanIn: " + this.getFanIn() + "\nFanOut: " + this.getFanOut() + "\nComplexity: " + this.getComplexity();
                txt.IsReadOnly = true;

                vb.Child = txt;
                surfaceWindow.ClassScatter.Items.Add(vb);
                this.setExpanded(true);
            }
        }

这很好用,但遗憾的是,我无法更改大小,移动或旋转创建的对象。任何提示为什么?

1 个答案:

答案 0 :(得分:1)

问题是你的TextBox捕获了触摸接触,而ScatterView无法捕获它们来拖动/缩放/旋转TextBox。有两种方法可以解决您的问题:

  1. 如果您希望项目可移动但用户无法编辑,请将SurfaceTextBox替换为常规TextBlock
  2. 如果您仍希望文本可编辑,请在TextBox中添加一些边距,以在元素周围创建“拖动区域”。例如:txt.Margin = new Thickness(20);