![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Programmatic object creation I would like to create WPF objects programmatically. Does anyone know of a tutorial for this? For example, I would to do something like... Ellipse myEllipse = new Ellipse(); Unfortunately, I can't get this syntax to compile. Ideally I would be able to create and define a particular kind of object in XAML/C# and then instantiate it. It appears like I need to create a resource defintion in XAML and associate it with my codebehind? I'm not finding examples of this and haven't been able to hack something together on my own. I tried the free cell sample, but this implementation seems rather abstruse to me. Can anyone point me to a more basic example? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Programmatic object creation peter wrote: > I would like to create WPF objects programmatically. Does anyone know > of a tutorial for this? For example, I would to do something like... > > Ellipse myEllipse = new Ellipse(); > > Unfortunately, I can't get this syntax to compile. Ideally I would be > able to create and define a particular kind of object in XAML/C# and > then instantiate it. It appears like I need to create a resource > defintion in XAML and associate it with my codebehind? I'm not finding > examples of this and haven't been able to hack something together on > my own. > > I tried the free cell sample, but this implementation seems rather > abstruse to me. Can anyone point me to a more basic example? Thanks. You should definitely be able to do exactly what you're trying to do. It's a very straightforward programming model. What erros are you getting? -Drew ___________________________________ Drew Marsh Chief Software Architect Mimeo.com, Inc. - http://www.mimeo.com Microsoft C# / WPF MVP Weblog - http://blog.hackedbrain.com/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Programmatic object creation Compiler says that Ellipse is a 'field' but is used like a 'type'? I do have an Ellipse in my xaml so I suppose it thinks I'm trying to instantiate an instance rather than a class definition? But isn't Ellipse a WPF type? How do I refer to the type? Thanks! Peter "Drew Marsh" wrote: > peter wrote: > > > I would like to create WPF objects programmatically. Does anyone know > > of a tutorial for this? For example, I would to do something like... > > > > Ellipse myEllipse = new Ellipse(); > > > > Unfortunately, I can't get this syntax to compile. Ideally I would be > > able to create and define a particular kind of object in XAML/C# and > > then instantiate it. It appears like I need to create a resource > > defintion in XAML and associate it with my codebehind? I'm not finding > > examples of this and haven't been able to hack something together on > > my own. > > > > I tried the free cell sample, but this implementation seems rather > > abstruse to me. Can anyone point me to a more basic example? Thanks. > > You should definitely be able to do exactly what you're trying to do. It's > a very straightforward programming model. What erros are you getting? > > -Drew > ___________________________________ > Drew Marsh > Chief Software Architect > Mimeo.com, Inc. - http://www.mimeo.com > Microsoft C# / WPF MVP > Weblog - http://blog.hackedbrain.com/ > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Programmatic object creation Do you have <Ellipse Name="Ellipse" /> ? The names you specify as you have discovered will appear as fields from your code-behind. However, that should still work. I'm guessing you are missing a namespace import. Do you have "using System.Windows.Shapes;" ? - Doug > Compiler says that Ellipse is a 'field' but is used like a 'type'? I > do have an Ellipse in my xaml so I suppose it thinks I'm trying to > instantiate an instance rather than a class definition? But isn't > Ellipse a WPF type? How do I refer to the type? > > Thanks! > > Peter > > "Drew Marsh" wrote: > >> peter wrote: >> >>> I would like to create WPF objects programmatically. Does anyone >>> know of a tutorial for this? For example, I would to do something >>> like... >>> >>> Ellipse myEllipse = new Ellipse(); >>> >>> Unfortunately, I can't get this syntax to compile. Ideally I would >>> be able to create and define a particular kind of object in XAML/C# >>> and then instantiate it. It appears like I need to create a resource >>> defintion in XAML and associate it with my codebehind? I'm not >>> finding examples of this and haven't been able to hack something >>> together on my own. >>> >>> I tried the free cell sample, but this implementation seems rather >>> abstruse to me. Can anyone point me to a more basic example? Thanks. >>> >> You should definitely be able to do exactly what you're trying to do. >> It's a very straightforward programming model. What erros are you >> getting? >> >> -Drew >> ___________________________________ >> Drew Marsh >> Chief Software Architect >> Mimeo.com, Inc. - http://www.mimeo.com >> Microsoft C# / WPF MVP >> Weblog - http://blog.hackedbrain.com/ |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Programmatic object creation Duh... good guess. Thanks. Still, I'd say there are several things that could be improved here. First of all, the compiler didn't suggest that I might be missing a using statement as it usually does and instead gave me the worthless bracket missing error. Also, it is interesting that I can add an Ellipse in XAML without importing the library. Does VS do this for you when you add a control from the toolbox to the designer? I'm not sure. Maybe this this is deliberate? Peter "Douglas Stockwell" wrote: > Do you have <Ellipse Name="Ellipse" /> ? > > The names you specify as you have discovered will appear as fields from your > code-behind. > > However, that should still work. I'm guessing you are missing a namespace > import. > > Do you have "using System.Windows.Shapes;" ? > > - Doug > > > Compiler says that Ellipse is a 'field' but is used like a 'type'? I > > do have an Ellipse in my xaml so I suppose it thinks I'm trying to > > instantiate an instance rather than a class definition? But isn't > > Ellipse a WPF type? How do I refer to the type? > > > > Thanks! > > > > Peter > > > > "Drew Marsh" wrote: > > > >> peter wrote: > >> > >>> I would like to create WPF objects programmatically. Does anyone > >>> know of a tutorial for this? For example, I would to do something > >>> like... > >>> > >>> Ellipse myEllipse = new Ellipse(); > >>> > >>> Unfortunately, I can't get this syntax to compile. Ideally I would > >>> be able to create and define a particular kind of object in XAML/C# > >>> and then instantiate it. It appears like I need to create a resource > >>> defintion in XAML and associate it with my codebehind? I'm not > >>> finding examples of this and haven't been able to hack something > >>> together on my own. > >>> > >>> I tried the free cell sample, but this implementation seems rather > >>> abstruse to me. Can anyone point me to a more basic example? Thanks. > >>> > >> You should definitely be able to do exactly what you're trying to do. > >> It's a very straightforward programming model. What erros are you > >> getting? > >> > >> -Drew > >> ___________________________________ > >> Drew Marsh > >> Chief Software Architect > >> Mimeo.com, Inc. - http://www.mimeo.com > >> Microsoft C# / WPF MVP > >> Weblog - http://blog.hackedbrain.com/ > > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Inherit from usercontrol - Object not set to instance of an object | .NET General | |||
| Failing Object creation from vbs-script on Windows Server 2008 | VB Script | |||
| datalist -- Object reference not set to an instance of an object. | .NET General | |||
| Testing object arrays using Compare-Object and -contains | PowerShell | |||
| Adding canonical aliases for Compare-Object, Measure-Object, New-Object | PowerShell | |||