I have the below xaml that I am trying to bind to my class. I am having trouble getting the values to show up. Can anyone point me in the direction of what I am missing. Thank you in advance.
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
开发者_JAVA技巧Part_Description = Part.ITEM_DESC
End Sub
End Class
<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>
In the ouput window I get the below error message:
Cannot get 'Part_Id' value (type 'System.String') from 'SNC.CommonStock.SelectedPart' (type 'SNC.CommonStock.SelectedPart'). BindingExpression: Path='Part_Id' DataItem='SNC.CommonStock.SelectedPart' (HashCode=53866394); target element is 'System.Windows.Controls.Label' (Name=''); target property is 'Content' (type 'System.Object').. System.MethodAccessException: Attempt by method 'System.Windows.CLRPropertyListener.get_Value()' to access method 'SNC.CommonStock.SelectedPart.get_Part_Id()' failed.
The labels are all on top of one another at present, if there is no description then potentially you'll see no content. Place the labels in a StackPanel
.
I had to make the class I was binding to public
精彩评论