我有以下xaml,我试图绑定到我的班级。我无法让值显示出来。任何人都可以指出我所缺少的方向。提前谢谢。
Dim frm As New EditPart
frm.DataContext = New SelectedPart(_CPPartPicker.Selected_Part, "ABC")
frm.Show()
Class SelectedPart
Property Part_Key As Integer
Property Part_Id As String
Property Part_Rev As String
Property Whse As String
Property Part_Description As String
Sub New(Part As SNC.SL.Common.CP_Item.CP_Item_Lookup_Version_1Item_Lookup_Response, Whse As String)
Part_Key = Part.ITEM_KEY
Part_Id = Part.ITEM_ID
Part_Rev = Part.ITEM_RVSN_ID
Whse = Whse
Part_Description = Part.ITEM_DESC
End Sub
结束班
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<sdk:Label Content="{Binding Path=Part_Id, StringFormat='Part ID: \{0}'}" />
<sdk:Label Content="{Binding Path=Part_Rev, StringFormat='Part Rev: \{0}'}" />
<sdk:Label Content="{Binding Path=Part_Description, StringFormat='Description: \{0}'}"/>
<Button x:Name="CancelButton" Content="Cancel" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
<Button x:Name="OKButton" Content="OK" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
</Grid>
在输出窗口中,我收到以下错误消息:
无法从'SNC.CommonStock.SelectedPart'获取'Part_Id'值(类型'System.String')(输入'SNC.CommonStock.SelectedPart')。 BindingExpression:Path ='Part_Id'DataItem ='SNC.CommonStock.SelectedPart'(HashCode = 53866394); target元素是'System.Windows.Controls.Label'(Name =''); target属性为'Content'(类型'System.Object').. System.MethodAccessException:尝试通过方法'System.Windows.CLRPropertyListener.get_Value()'访问方法'SNC.CommonStock.SelectedPart.get_Part_Id()'失败。
答案 0 :(得分:2)
目前标签都是彼此重叠的,如果没有说明,那么你可能看不到任何内容。将标签放在StackPanel
。
答案 1 :(得分:0)
我不得不把我绑定到公开的课程