0
我有使用WPF和vb.net進行數據綁定的問題。其實,我嘗試使用WPF(xaml)和C#,它工作得很好。但是,當我想使用vb.net構建它時,我遇到了一個問題,即數據是空的,沒有顯示任何內容。因此,我非常肯定,它與WPF和VB.net之間的數據綁定有關。如果有人能夠發現我在編碼過程中發生的錯誤,我將非常感激。提前致謝。 的VB.net代碼:數據綁定WPF和vb
Imports System.Collections.ObjectModel
Imports System.Windows
Imports System.Windows.Controls
Imports System.IO
Namespace chartTest
Public Class MainWindow
Public Sub New()
InitializeComponent()
Dim Errors As New TestPageViewModel()
Errors = Me.DataContext
End Sub
Public Class TestPageViewModel
Public m_Errors As ObservableCollection(Of DataChart)
Public Property Errors() As ObservableCollection(Of DataChart)
Get
Return m_Errors
End Get
Private Set(value As ObservableCollection(Of DataChart))
m_Errors = value
End Set
End Property
Public Sub addDataChart()
Errors = New ObservableCollection(Of DataChart)()
Errors.Add(New DataChart() With { _
.Category = "Globalization", _
.Number = 75 _
})
Errors.Add(New DataChart() With { _
.Category = "Features", _
.Number = 2 _
})
Errors.Add(New DataChart() With { _
.Category = "ContentTypes", _
.Number = 12 _
})
Errors.Add(New DataChart() With { _
.Category = "Correctness", _
.Number = 83 _
})
Errors.Add(New DataChart() With { _
.Category = "Best Practices", _
.Number = 29 _
})
End Sub
Private m_selectedItem As Object = Nothing
Public Property SelectedItem() As Object
Get
Return m_selectedItem
End Get
Set(value As Object)
m_selectedItem = value
End Set
End Property
End Class
' class which represent a data point in the chart
Public Class DataChart
Private m_Category As String
Public Property Category() As String
Get
Return m_Category
End Get
Set(value As String)
m_Category = value
End Set
End Property
Private m_Number As Integer
Public Property Number() As Integer
Get
Return m_Number
End Get
Set(value As Integer)
m_Number = value
End Set
End Property
End Class
End Class
End Namespace
的XAML代碼如下:
<Window x:Class="chartTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:chart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"
xmlns:local="clr-namespace:chartTest.chartTest"
>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Generic.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="73*"/>
<RowDefinition Height="7*"/>
</Grid.RowDefinitions>
<chart:PieChart
ChartTitle="Minimal Pie Chart"
ChartSubTitle="Chart with fixed width and height"
SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}" Grid.RowSpan="2" >
<chart:PieChart.Series>
<chart:ChartSeries
SeriesTitle="Errors"
DisplayMember="Category"
ValueMember="Number"
Width="400"
Height="400"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ItemsSource="{Binding Path=Errors}"/>
</chart:PieChart.Series>
</chart:PieChart>
</Grid>
</Window>
我改變了它,但我仍然有一個空的圖表。這意味着數據綁定不能從xaml正確調用。任何其他建議! – Mahmoud 2015-02-05 15:49:37