-1
要麼它超級簡單,我只是沒有找到解決方案,否則我很快就會開始瘋狂。將Ellipse放在同一視圖中的一條線的邊緣
我只是想在Canvas
繪製的ItemsControl
一個Line
和Line
應該對兩邊的Ellipse
。就像這樣:
我的ItemsControl看起來是這樣的:
<ItemsControl ItemsSource="{Binding Connections}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type systemEnvironmentViewModels:SystemEnvironmentConnectionViewModel}">
<systemEnvironment:ConnectionView/>
</DataTemplate>
<Style TargetType="ContentPresenter"> <!-- this does only make it worse -->
<Setter Property="Canvas.Left" Value="{Binding Connection.FirstElementCoordinate.X}"/>
<Setter Property="Canvas.Top" Value="{Binding Connection.FirstElementCoordinate.Y}"/>
</Style>
</ItemsControl.Resources>
</ItemsControl>
,這是作爲DataTemplate中查看:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Ellipse x:Name="DependencyEllipse" Width="10" Height="10" Fill="Black" Grid.Column="0"/>
<Line X1="{Binding Connection.FirstElementCoordinate.X}" X2="{Binding Connection.SecondElementCoordinate.X}"
Y1="{Binding Connection.FirstElementCoordinate.Y}" Y2="{Binding Connection.SecondElementCoordinate.Y}"
Stroke="Black" StrokeThickness="5" x:Name="ConnectionLine" Grid.Column="1"/>
<Ellipse x:Name="SecondDependencyEllipse" Width="10" Height="10" Fill="Black" Grid.Column="2"/>
</Grid>
結果看起來一點也不像我想和我知道在列中使用Grid
可能不起作用,但它是我能想到的最接近的,可以像我想要的那樣拆分元素。
另外,Style
爲ContentPresenter
似乎是錯誤的,因爲沒有它,我行被抽像我想要,但Ellipses
是錯誤的
我應該去另一個ItemsControl的只是爲橢圓? 非常感謝幫助。
非常感謝!似乎還有很多需要了解WPF的知識。 – fbueckle
不客氣。確實有很多東西需要學習,這就是爲什麼有一些非常好的WPF書籍。值得閱讀其中的一兩個。單靠StackOverflow是不夠的。 – Clemens
你能推薦一本或多本書嗎? – fbueckle