コンポーネントのラインナップキャンバスにスケーリング/Transform合わせ

StackOverflow https://stackoverflow.com/questions/2236865

  •  19-09-2019
  •  | 
  •  

質問

私は転載この問いと思っているが、対応の最終時間は、今、ビットの文言が...

基本的にどのようにしているいは開発キャンバス、自動的に規模でその内容を必ず記入し、ご利用スペース。のようズームを合わせます。残念ながら私のコンポーネントのラインナップ能力のない非常に強く、どうしたらいいのかと悩んしていけるかを切り開いていくないこの前ます。今後もdatabinding例のキャンバスの行きがないか、誤を妨げました。

私には二つの基本的な問題の方法によってどのように取り組む、ソリューションのいずれかの

  • わからないか、 キャンバスの再規模で自動的に 通話サイトの最新トレンドの場合にその可能性を 変換した。
  • ことはできるのか? 参考のキャンバスの裏側 コードは、私の推測ではその一部 のItemsControl?

例えんを達成しようと思っていたいしてみるB:

(除了しましたリンクimg)

このコードを使っていはいたってシンプルで作成4ドットの指定された調整、別のビューモデルラップされます。

public class PointCollectionViewModel
{
    private List<PointViewModel> viewModels;
    public PointCollectionViewModel()
    {
        this.viewModels = new List<PointViewModel>();
        this.viewModels.Add(new PointViewModel(new Point(1, 1)));
        this.viewModels.Add(new PointViewModel(new Point(9, 9)));
        this.viewModels.Add(new PointViewModel(new Point(1, 9)));
        this.viewModels.Add(new PointViewModel(new Point(9, 1)));
    }

    public List<PointViewModel> Models
    {
        get { return this.viewModels; }
    }
}

public class PointViewModel
{
   private Point point;
   public PointViewModel(Point point)
   {
       this.point = point;
   }

   public Double X { get { return point.X; } }
   public Double Y { get { return point.Y; } }
}

その後、PointCollectionViewModelを使用していDataContentっAutoResizingCanvasは、以下のポス実施のためbinding:

<UserControl x:Class="WpfCanvasTransform.AutoResizingCanvas"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfCanvasTransform"
    x:Name="parent">
    <ItemsControl x:Name="itemsControl" ItemsSource="{Binding Path=Models}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
        <Canvas x:Name="canvas" Background="DarkSeaGreen" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
            <Canvas.LayoutTransform>
            <ScaleTransform ScaleY="-1" />
            </Canvas.LayoutTransform>

        </Canvas>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate DataType="{x:Type local:PointViewModel}">
        <Ellipse Width="3" Height="3" Fill="Red"/>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemContainerStyle>
        <Style>
        <Setter Property="Canvas.Top" Value="{Binding Path=Y}"/>
        <Setter Property="Canvas.Left" Value="{Binding Path=X}"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
    </ItemsControl>
</UserControl>
役に立ちましたか?

解決

としてお Canvas ように見えませんの固定幅と高さで、こちらをご覧ください込 Viewbox:

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <Viewbox Stretch="Uniform">
            <Canvas x:Name="canvas" Background="DarkSeaGreen">
                <Canvas.LayoutTransform>
                <ScaleTransform ScaleY="-1" />
                </Canvas.LayoutTransform>
            </Canvas>
        </Viewbox>
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

また、全体 UserControlViewBox.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top