Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Expose parameters for my user control in top level XAML Layout ?

 
 
Old 01-10-2006   #1 (permalink)
Griff


 
 

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#)

My System SpecsSystem Spec
Old 01-10-2006   #2 (permalink)
Jason Dolinger


 
 

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
My System SpecsSystem Spec
Old 01-10-2006   #3 (permalink)
Rob Relyea [MSFT]


 
 

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



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
User Account Control (UAC) - Elevate Privilege Level Tutorials
folder level layout Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46