![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Expose parameters for my user control in top level XAML Layout ? Suppose I have a usercontrol "myButton" I want someone to be able to use this control it in their XAML layout with <some container> <local:myButton param1="value1" param2="value2" /> </some container> I want param1 etc to hold a values (integer, string or Brush) that will be used in the layout of the control in the XAML but also available to the usercontrol code behind. How do I go about setting up these parameters in the "myButton" definition ? Simply having a property (or a dependency property) in the XAML/c# code for the control doesn't seem to make these parameters accessible. -- Griff (Learning to make industrial UI with XAML/WPF/c#) |
| | #2 (permalink) |
| Guest | RE: Expose parameters for my user control in top level XAML Layout ? I think you are looking for attached dependency properties. Look into the documentation, it's the same concept behind Grid.Row or Grid.Column properties. Valentin "Griff" wrote: > Suppose I have a usercontrol "myButton" > > I want someone to be able to use this control it in their XAML layout with > > <some container> > <local:myButton param1="value1" param2="value2" /> > </some container> > > I want param1 etc to hold a values (integer, string or Brush) that will be > used in the layout of the control in the XAML but also available to the > usercontrol code behind. > > How do I go about setting up these parameters in the "myButton" definition ? > Simply having a property (or a dependency property) in the XAML/c# code for > the control doesn't seem to make these parameters accessible. > > -- > Griff > (Learning to make industrial UI with XAML/WPF/c#) |
| | #3 (permalink) |
| Guest | Re: Expose parameters for my user control in top level XAML Layout? Griff wrote: > Suppose I have a usercontrol "myButton" > > I want someone to be able to use this control it in their XAML layout with > > <some container> > <local:myButton param1="value1" param2="value2" /> > </some container> > > I want param1 etc to hold a values (integer, string or Brush) that will be > used in the layout of the control in the XAML but also available to the > usercontrol code behind. > > How do I go about setting up these parameters in the "myButton" definition ? > Simply having a property (or a dependency property) in the XAML/c# code for > the control doesn't seem to make these parameters accessible. > Griff, Perhaps you need to add CLR wrappers around the property? I've seen that recommended in most custom control development documentation that I've seen (which is scant!). For example: public class CustomControl : UserControl { // Dependency Property public static readonly DependencyProperty Param1Property = DependencyProperty.Register("test", typeof(int), typeof(CustomControl), etc... // CLR wrapper for DP public int Param1 { get { return (int) GetValue (Param1Property); } set { SetValue (Param1Property, value); } } } Jason |
| | #4 (permalink) |
| Guest | Re: Expose parameters for my user control in top level XAML Layout ? Yes, you need static set and get methods for any attached property as Jason recommends. Thanks, Rob Relyea WPF Program Manager http://longhornblogs.com/rrelyea "Jason Dolinger" <jdolinger@lab49.com> wrote in message news:%23x8HiUkBGHA.2704@TK2MSFTNGP15.phx.gbl... > Griff wrote: >> Suppose I have a usercontrol "myButton" >> >> I want someone to be able to use this control it in their XAML layout >> with <some container> >> <local:myButton param1="value1" param2="value2" /> >> </some container> >> >> I want param1 etc to hold a values (integer, string or Brush) that will >> be used in the layout of the control in the XAML but also available to >> the usercontrol code behind. >> >> How do I go about setting up these parameters in the "myButton" >> definition ? >> Simply having a property (or a dependency property) in the XAML/c# code >> for the control doesn't seem to make these parameters accessible. >> > > Griff, > > Perhaps you need to add CLR wrappers around the property? I've seen that > recommended in most custom control development documentation that I've > seen (which is scant!). > > For example: > > public class CustomControl : UserControl > { > > // Dependency Property > public static readonly DependencyProperty Param1Property = > DependencyProperty.Register("test", typeof(int), typeof(CustomControl), > etc... > > > // CLR wrapper for DP > public int Param1 > { > get { return (int) GetValue (Param1Property); } > set { SetValue (Param1Property, value); } > } > > } > > > Jason |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User Account Control (UAC) - Elevate Privilege Level | Brink | Tutorials | 27 | 2 Hours Ago 12:08 PM |
| folder level layout | Perecli Manole | Vista file management | 5 | 04-25-2007 10:28 AM |
| Confusing Control Panel Layout | Bill G. | Vista General | 3 | 09-29-2006 08:28 AM |
| Expose properties of "sub controls" in control template | Matt Mitchell | Avalon | 2 | 03-04-2006 04:08 PM |