Rick wrote:
First of all, is there a group more specific to WPF?
No, Microsoft seems to favour web forums for any new stuff.
I have a WPF form and I want to bind to a local member variable from the
xaml.
the code behind is like this:
Partial Public Class MyClass
Public Property MyProp as system.xml.XmlDocument
get...
set...
end property
Then in the xaml I want to bind to a grid like this:
<Grid.DataContext>
<XmlDataProvider Source="{MyProp}" XPath="profiles" />
</Grid.DataContext>
but I get a Intellisence notice that "type MyProp cannot be found..."
I have also tried {x:Static MyProp} which also does not work.
How do I refer to a public property in my own class?
It is not clear what you want to achieve. The Source property of an
XmlDataProvider takes a Uri and not an XmlDocument. If you have an
XmlDocument then you would need to set the Document property, not the
Source property. I am not sure whether you can do that in XAML, here is
how you could do that in code:
Foo.vb:
Imports System.Xml
Public Class Foo
Private _doc As XmlDocument
Public Property Doc() As XmlDocument
Get
Return _doc
End Get
Set(ByVal value As XmlDocument)
_doc = value
End Set
End Property
End Class
Window1.xaml.vb:
Imports System.Xml
Class Window1
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Dim xdp1 As XmlDataProvider = CType(Me.Resources("xdp1"),
XmlDataProvider)
Dim foo1 As New Foo()
foo1.Doc = New XmlDocument()
foo1.Doc.LoadXml("<root><item>1</item><item>2</item><item>3</item></root>")
xdp1.Document = foo1.Doc
End Sub
End Class
Window1.xaml:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<XmlDataProvider x:Key="xdp1" XPath="root"/>
</Window.Resources>
<StackPanel>
<ListBox ItemsSource="{Binding Source={StaticResource xdp1},
XPath=item}"></ListBox>
</StackPanel>
</Window>
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/