感谢大家让我开始!因此,我最终创建了一个ObservableCollection类&将我的列表框绑定到该类的一个属性(attribute标记)…到目前为止,一切似乎都正常工作。WPF/XAML山很难攀登…
- Private Sub SelectTargetedBlock_Click(sender As Object, e As Windows.RoutedEventArgs) Handles SelectTargetedBlock.Click
- Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
- Dim ed As Editor = doc.Editor
- Dim db As Database = doc.Database
- 'this - is the modal dialog box.
- Using UI As EditorUserInteraction = ed.StartUserInteraction(Me)
- Dim entResult As PromptEntityResult = ed.GetEntity(vbLf & "Select entity")
- If entResult.Status PromptStatus.OK Then
- Return
- End If
- Using Tx As Transaction = db.TransactionManager.StartTransaction()
- ' Dim obj As DBObject = Tx.GetObject(entResult.ObjectId, OpenMode.ForRead)
- Dim BlkRef As BlockReference = Tx.GetObject(entResult.ObjectId, OpenMode.ForRead)
- If BlkRef.AttributeCollection IsNot Nothing Then
- Dim attCol As AttributeCollection = BlkRef.AttributeCollection
- For Each attId As ObjectId In attCol
- Dim attRef As AttributeReference = TryCast(Tx.GetObject(attId, OpenMode.ForRead), AttributeReference)
- MyObjectSource.Add(New MyAttribute With {
- .BlkTagToLookAt = attRef.Tag,
- .DestinationBlkName = attRef.BlockName})
- Next
- End If
- Tx.Commit()
- End Using
- End Using
- Dim b As New Binding("BlkTagToLookAt")
- b.Mode = BindingMode.OneWay
- b.Source = MyObjectSource
- BindingOperations.SetBinding(MyListBox, TextBox.TextProperty, b)
- MyListBox.DataContext = MyObjectSource
|