我坚持将折线的点绑定到 ObservableCollection(Of Point):
<UserControl
x:Class="GL.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="640" d:DesignWidth="840">
<Grid x:Name="LayoutRoot" Background="#ff444444">
<Canvas Background="#333333" Width="800" Height="600">
<Polyline x:Name="Linie" Stroke="Yellow" StrokeThickness="2" Canvas.Left="0" Canvas.Top="0" Width="800" Height="600" Fill="Gray" Points="{Binding Punkte}">
</Polyline>
</Canvas>
<TextBlock Height="55" Name="tb" Foreground="White" FontSize="{Binding Path=TS}" Text="JUST A TEST!" />
<Button Content="Add Point" Height="23" HorizontalAlignment="Left" Margin="745,617,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />
</Grid>
这是后面的代码:
Imports System.Windows
Imports System.Windows.Media
Imports System.Collections.ObjectModel
Partial Public Class MainPage
Inherits UserControl
Dim r As New Random(345)
Private _punkte As New ObservableCollection(Of Point)
Public Property Punkte As ObservableCollection(Of Point)
Get
Return _punkte
End Get
Set(value As ObservableCollection(Of Point))
_punkte = value
SetValue(Punkte_DP, _punkte)
End Set
End Property
Private _ts As Integer
Public Property TS As Integer
Get
Return _ts
End Get
Set(value As Integer)
_ts = value
SetValue(TS_DP, _ts)
End Set
End Property
Public Punkte_DP As DependencyProperty = DependencyProperty.Register("Punkte", GetType(ObservableCollection(Of Point)), GetType(MainPage), New PropertyMetadata(New ObservableCollection(Of Point)))
Public TS_DP As DependencyProperty = DependencyProperty.Register("TS", GetType(Integer), GetType(MainPage), New PropertyMetadata(New Integer))
Public Sub New()
Me.DataContext = Me
InitializeComponent()
Linie.DataContext = Me.Punkte
Punkte.Add(New Point(100, 100))
Punkte.Add(New Point(700, 300))
TS = 25
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Punkte.Add(New Point(r.Next(0, 600), r.Next(0, 600)))
End Sub
End Class
当我运行它时,FontSize 得到更新,但没有一个点响应。正在绘制的线。每次单击按钮时集合都会变大,但没有任何反应。
我到底在这里想念什么?谢谢你的帮助!
问候, 罗伯