1

線分のリストがあり、各線分には点のリストが含まれています。同じキャンバスに含まれているので、各線分を表示し、同時に各点の位置をマークしたい(つまり、楕円で)。ItemsControl を使用してセグメントを表示できますが、ポイントを表示する方法に行き詰まっています。Shape から派生したカスタム コントロールの実装を開始しましたが、もっと簡単な方法があるはずです。助けてくれてありがとう。

public class VesselAnatomy : IEnumerable, INotifyCollectionChanged
{
...
List<BaseVessel> _Segments;
...
}

public class BaseVessel : INotifyPropertyChanged
{
...
ObservableCollection<Point> _VesselPoints;
public ObservableCollection<Point> VesselPoints
        {
            get
            {
                return _VesselPoints;
            }
        }
...
}

public MainWindow()
{
...
VesselAnatomy Vessels = new VesselAnatomy();
...
MasterContainer.DataContext =  Vessels;
...
}

<ItemsControl x:Name="VesselDisplay"
                          Height="750"
                          Width="750"
                      ItemsSource="{Binding}">
                        <Polyline Points="{Binding VesselPoints, Converter={StaticResource ObsListPointConverter}}"
                            Stroke="Red"
                            StrokeThickness="7">
                            <Polyline.ToolTip>
                                <ToolTip>
                                    <TextBlock Text="{Binding Name}"/>
                                </ToolTip>
                            </Polyline.ToolTip>
                        </Polyline>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
4

1 に答える 1

0

ポイントに ItemsControl を使用することも、ItemsPanel を変更して要素の位置をバインドすることもできます。

<Window ... >
    <Window.Resources>
        <PointCollection x:Key="points">
            <Point X="20" Y="20" />
            <Point X="40" Y="35" />
            <Point X="60" Y="40" />
            <Point X="80" Y="60" />
            <Point X="100" Y="40" />
            <Point X="120" Y="30" />
            <Point X="140" Y="40" />
            <Point X="160" Y="20" />
        </PointCollection>
        <DataTemplate DataType="{x:Type Point}">
            <Ellipse Width="9" Height="9" Fill="White" Stroke="DodgerBlue" StrokeThickness="1" x:Name="e">
                <Ellipse.RenderTransform>
                    <TransformGroup>
                        <TranslateTransform X="-4" Y="-4" />
                        <TranslateTransform X="{Binding X}" Y="{Binding Y}" />
                    </TransformGroup>
                </Ellipse.RenderTransform>
            </Ellipse>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Polyline x:Name="line" Stroke="LightBlue" StrokeThickness="2" Points="{StaticResource points}" /> 
        <ItemsControl x:Name="ptsdisplay" ItemsSource="{StaticResource points}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </Grid>
</Window>

ポイントがたくさんあり、この方法が遅すぎる場合は、http://msdn.microsoft.com/en-us/magazine/dd483292.aspxを試してください

于 2011-05-10T00:36:37.620 に答える