WPF refer to local member variable for databinding

First of all, is there a group more specific to WPF?

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?

Rick 

0
Rick2256 (24)
10/10/2008 11:08:20 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
662 Views

Similar Articles

[PageSpeed] 56

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/
0
mahotrash (1778)
10/10/2008 11:45:05 AM
"Martin Honnen" <mahotrash@yahoo.de> wrote in message 
news:uo%23Tm2sKJHA.3744@TK2MSFTNGP06.phx.gbl...
> 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/

Thanks Martin,

Sorry, yes I need to set the Document property not the Source.  I can do 
this in code already, however just as an exercise I wanted to do it in xaml 
since I am just learning and want to see if it is possible.  There must be 
some way to refer to the code-behind in the xaml, but I can't seem to find 
it yet.

I'll keep looking. 

0
Rick2256 (24)
10/10/2008 12:29:35 PM
Reply:

Similar Artilces:

XML Serialisation & Circular References
I have been able to get simple circular references to be serialized in xml by using the ImportTypeMapping method on the SoapReflectionImporter class. But I am unable to serialise circular references when the circular reference is contained with in a collection class, specifically I am using a custom ArrayList object. I keep getting a StackOverFlow Exception from the XmlSerializer class when attempting the serialisation. The classes are: Class A, Class B - this is derived from System.Collection.ArrayList Class C. Class A contains an instance of B Class B contains multiple instances of C Cl...

Circular Reference when opening program
When my program opens, I get a notice that there is a circular reference. My program automatically goes to a 'welcome sheet' when opening, and when I cancel the message, the welcome sheet appears, and I cannot figure out how to find that circular reference. The circular reference toolbar appears, but there is no cell displayed. It is a very large program, and seems to work well in general, but there are a lot of options and a lot of formulas and I do not know how to find the cell that is causing this error message. I do not know what page the reference is on, or if it is i...

map smb share as local unit
hi guys I need to mount/map a smbshare (\\smbshare\myfolder) as a local unit (G:). please, note: *local* unit. windows must believe that I am using a local unit, not a network unit. Some software I am using needs this. I hate it, but I cannot change it. ok. I found a software named NetDrive, that does exactly what I need with FTP servers (it lacks the "bidirectional" behavior, by the way: if i change something on the "virtual local unit", the change reflects suddenly on FTP server, but if i change something onto the remote server, I must shutdown and...

Using derived classes as member variables works...sometimes
suppose i derive CMyDlg from CDialog, then I want to use a CMyDlg object as a member variable of my main window (dialog based app). I add a member variable of the type CMyDlg with the name myDlg, then later I use the variable myDlg to call methods, retrieve data, etc....so why is it that when I compile the code, I get errors that indicate that my compiler has no idea what a CMyDlg is? IE: "error C2146: syntax error : missing ';' before identifier 'myDlg'"; and "error C2501: 'CMyDlg' : missing storage-class or type specifiers" I at times done...

WPF and XBAP
I red http://msdn.microsoft.com/en-us/library/aa970060.aspx to learn WPF. I have some questions below. 1) Can I create a new project using WPF application template instead of WPF Browser Application (once done, convert to XBAP)? 2) If I have to use WPF Browser Application template, can I use all winform controls? 3) If I have to use WPF Browser Application template, can I use ASP.NET controls? -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201001/1 "aspfun via DotNetMonster.com" <u53138@uwe> wrote in news:a...

Rule Engine Reference
Hi there, we are using CRM 3.0 Small Business Edition - but there is only minimal online documentation available. Can I download documentation, especially the Rule Engine reference, somewhere from Microsoft? Kind regards, Robert Two good references to have would be Mike Snyder's book "Working with Microsoft Dynamics CRM 3.0" and the Microsoft Official Curriculum for CRM for the Microsoft course #8525 which you can order from a Microsoft training partner or your CRM partner. -- Matt Wittemann, CRM MVP http://icu-mscrm.blogspot.com "Robert" wrote: > Hi the...

Cross-Reference Color
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I have inserted cross-references to Tables, Figures, and Headings in my Word documents and want the cross-references to be in blue because they are active hyperlinks. I've created a character style called Xref which just changes the font color. It works perfectly on my PC, and seems to work on the MAC until I save the document - then the cross-references return to black. <br><br>Am I missing something? How do I get my cross-references to remain blue? <br><br>Thanks, <br><br&...

WPF Textbox won't wrap
As in the subject. I create a simple textbox and set the TextWrapping="Wrap". No wouldn't one expect wrapping for the text? Goggling does not bring much help and as an aside the searching for WPF and textbox is getting much more difficult because websites now want to have as many keywords as possible so every search for "textbox wpf wrap" brings windows controls pages. Nope. Why is everything in WPF so difficult? The number of lines of code I have written to make controls act similarly to windows controls is ridiculous. Thanks LS On 2010-0...

How to add multiple members in DL for Exchange 5.5
Hi, Is there any way to add multiple members in Exchange 5.5 distribution list, instead of selecting one at a time. Thanks! Directory import, available in Exchange administrator tool. Baris. -- This posting is provided "AS IS" with no warranties, and confers no rights. "San" <anonymous@discussions.microsoft.com> wrote in message news:f4a001c43de9$9cabde00$a401280a@phx.gbl... > Hi, > > Is there any way to add multiple members in Exchange 5.5 > distribution list, instead of selecting one at a time. > > Thanks! ...

Connection to local MSDE Database
I have a sql query made in the jscript OnSave event of the Appointment entity, which connects (using the ADODB) to the xxx_MSCRM database on the server to fetch data and put it into fields of the appointment. Obviously, this does not work when the client is using the Offline Outlook client. My question: I would like to change to connection string to point towards the local MSDE database when the client is using outlook, but don't know which server/Instance to use, and which credential to use. I've tried finding this local msde with a ODBC connection but can't connect to it. ...

insert WPF user control in ppt slide
Any way to insert WPF user control in ppt slide? Thanks, Vatia ...

histogram comparing two variables
I'm trying to graph an histogram to compare two variables with the same bins, although the ranges between the minimum and maximum are different. Anybody knows how to do it? Thanks! Hi Monica - On this web page, I describe how to make histograms, first using the Analysis Toolpack, then a more flexible way using your own worksheet formulas: http://peltiertech.com/Excel/Charts/Histograms.html Scroll down about 2/3 of the page to "Dynamic Do-It-Yourself Histograms". The nice thing about this approach is that you can set up your own bins, and calculate the frequencies of ...

Win Forms, WPF and Silverlight (?)
Hello. Amateur hour Webbiz here. :-) I'm in the middle of learning C# coming from VB6. Yes, it's a jump but a guy's got to move into the 21st Century eventually. Besides, in my past life (1980's) I was pretty familiar with C and C++ so learning the language part has been a breeze. However, .NET is a whole new world for me. Man, a lot has happened since the ole API days! While learning C# coding I'm getting familiar with my Visual Studio 2010 Pro IDE. Lots of strange files list that you have to get used to. Meanwhile, I've got a book open for WPF and ...

WPF DataBinding
I'm developing a fairly simple WPF solution. It's basically just a treeview on the left side, and a listview on the other. Very similar to Windows explorer in looking at the file system, but not with the file system. 8-) Anyway, here's my problem: My WPF listview has 5 columns. Each column has a name, and each column was databound using a simple custom expression. e.g.: <ListView.View> <GridView> <GridViewColumn Header="Column1" DisplayMemberBinding="{Binding A}"/> <GridViewColumn Header="Column2" Disp...

Sheet References in Cell
Is there a function that returns the name of a sheet, like sheet3, that appears on the sheet's tab? If you have saved the workbook =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,32) -- Regards, Peo Sjoblom "George L" <anonymous@discussions.microsoft.com> wrote in message news:7AFD0589-D27E-4C25-A52B-6035B23992AD@microsoft.com... > Is there a function that returns the name of a sheet, like sheet3, that appears on the sheet's tab? ...

Invalid cell reference
I am writing an Excel 2002 template, and wish to convert a large range of imported data. All of my formulae have been written in row A on a ‘Reformatted Data’ sheet. For example cell A1 contains =TEXT('Imported Data '!B3,"00"). The many formulae work successfully, but I need to delete the entire contents of the ‘Imported Data’ sheet. As a template it needs to be empty. Obviously the formulae in my example cell is now =TEXT('Imported Data '!#REF!,"00") because of the invalid cell reference. My question is, how do I retain the formulae in...

R1C1 Reference Style
I know how to turn the R1C1 Reference Style off and on, and have turned it off (I don't do macros). However, if I close Excel and then go back into it, I have to turn off the Reference Style again. How do I get it permantely off? Thanks! Jenny I think the reference style is set by the first book that is opened in Excel. Change the style and save the book. Andy. "Jenny" <jennifer.massey@siemens.com> wrote in message news:31a501c3d9ed$cb43a370$3101280a@phx.gbl... > I know how to turn the R1C1 Reference Style off and on, > and have turned it off (I don't do...

Adding References to a Project
Hi, I have an addin which I share with some work colleagues. I recently added a reference to the Microsoft Scripting Runtime to allow me to use the FileSystemObject. It opens the old version and imports a phone list into the new blank addin. Before I share the update I would like to figure out whether the new code will work on my colleagues machines without having to explicitly add the reference in their VBE? Is there a programmatic way to do so? Is it possible to use Application.Run instead of adding a reference? I've read a lot about references but haven't seen anything whic...

API for WPF
Hello all, I was wondering, is there an unmanaged API for using Windows Presentation Foundation (or WPF-like)? Regards. "Fernando G�mez" <fernando.a.gomez.f@gmail.com> wrote in message news:u3t2zLR4IHA.1204@TK2MSFTNGP04.phx.gbl... > Hello all, > > I was wondering, is there an unmanaged API for using Windows Presentation > Foundation (or WPF-like)? > I'm not sure how WPF-like it is, but here is a tantalizing abstract from an upcoming PDC talk: http://microsoftpdc.com/Agenda/Sessions.aspx --- Windows 7: Graphics Advances Windows 7 enables you to advan...

finding the results of changing 4 variables
Hi, I'm working on a 10 year financial forecasting model for an investment fund. The end result is to calculate the IRR. There are 4 variable inputs I would like to change, and observe how the IRR changes as those inputs change. In other words, I would like to play with changing two different fees, the fund size, and the expected return, and see how changing those impacts the IRR. Is there a way to do this on one sheet without manually changing all these inputs? I think Scenario or Data Tables might do it, but I'm not sure. Thank you. You might try this template...

Form/SubForm error while reference the object
I am a novice at Access and do not understand the VB codes. I have created a form (Software Register) with a subform (Licence No). I have created a one to many relationship between Software_ID_No in both forms. The Link Child and Link Master fields are populated with Software_ID_No. My subform (Licence No) now is linked to the main form (software Register) and moves with that form. What I want to do is have the Software_ID_No in the main form populate the Software_ID_No in the subform, and also put it into the Licence No Table. If I enter the number manually, it works. When I c...

Cell Names, References ?
I am attempting to re-work an existing worksheet that contains cells that have been "named". Does anyone know how to change or delete a name once entered into the "Name Box"? When I attempt to write over the names, I receive and error message regarding references. Thank you. -- tbryson ------------------------------------------------------------------------ tbryson's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=36246 View this thread: http://www.excelforum.com/showthread.php?threadid=560418 Use CTRL+F3 to bring up the Defined Name dia...

Local administrator privileges on CRM server?
Hi, I am installing a CRM Server 3.0 on my customer and apparently, the Active Directory account of the CRM Admin requieres Local Admin privileges on the CRM server (if not, there is a message: "Microsoft CRM Deployment Manager: Local Administrator provileges are required to use Deplyment Manager"). My customer disagrees with this, cause he does not want a "business user" to have such privileges on a Production Machine. Does anybody know a way to change this security configuration? Hugo. There is little that a "business user" would need to do in Deployme...

reference functions
I have a cell that is a pick list of items from a column. Those items are not values in themselves, but references to cells in various unpredictable locations on other sheets in the workbook. Example list column values: "Value 1" (refers to sheet1!A23) "Value 2" (refers to sheet2!B7) "Value 3" (refers to sheet2!D2) "Value 4" (refers to sheet3!A6) In this case the pick list would contain the choices Value 1, Value 2, Value 3, Value 4. When the user selects an item from the list, I need to get a reference to the cell that value came from, in order ...

Your formula contains an invalid external reference to a worksheet
I'm sure this has been asked before, but I've just wasted a whole day trying to find a solution and got nowhere! I have a complex spreadsheet which I inherited from my predecessor. It contains many sheets, plus macros, chart objects, text boxes, auto shapes, etc. When I try to close the spreadsheet it objects "Your formula contains an invalid external reference to a worksheet". Try as I might, I just can't pin this down. I've tried the obvious, such as searching formulae for '[', looking in named ranges and asigned macro names to no avail. In desperation ...