2011-09-09 133 views
1

我有下面的xaml,我试图绑定到我的课程。我无法使值显示出来。任何人都可以向我指出我失踪的方向。先谢谢你。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 'PART_ID' 值(类型 'System.String') .SelectedPart'(输入'SNC.CommonStock.SelectedPart')。 BindingExpression:Path ='Part_Id'DataItem ='SNC.CommonStock.SelectedPart'(HashCode = 53866394);目标元素是'System.Windows.Controls.Label'(Name =''); System.MethodAccessException:尝试通过方法'System.Windows.CLRPropertyListener.get_Value()'来访问方法'SNC.CommonStock.SelectedPart.get_Part_Id()'失败。

+0

它并没有的StringFormat –

+0

工作没有不与拆卸的StringFormat – Jim

回答

2

目前所有标签都相互重叠,如果没有说明,则可能会看到没有内容。将标签放在StackPanel中。

+0

我给的工作,在第一,但一个尝试没有解决问题。我刚刚在输出中看到这个错误 - 无法从'SNC.CommonStock.SelectedPart'(键入'SNC.CommonStock.SelectedPart')获得'Part_Id'值(输入'System.String')。 BindingExpression:Path ='Part_Id'DataItem ='SNC.CommonStock.SelectedPart'(HashCode = 53866394);目标元素是'System.Windows.Controls.Label'(Name =''); System.MethodAccessException:尝试通过方法'System.Windows.CLRPropertyListener.get_Value()'来访问方法'SNC.CommonStock.SelectedPart.get_Part_Id()'失败。 – Jim

+1

@Jim:我不做VB.NET,但在C#中类是内部的(我认为VB中的朋友说),属性是私人的,除非你另有指定。对于绑定工作,需要公开类和属性。所以我想知道是否需要将公共辅助功能添加到类和属性中。 – AnthonyWJones

+0

是的,是的。我在下面发布了我的答案。看起来我们在同一时间发布它:) – Jim

0

我不得不做出这个类,我结合公共