Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

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

Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
Griff
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#)
Old 01-10-2006   #2 (permalink)
viliescu
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#)

Old 01-10-2006   #3 (permalink)
Jason Dolinger
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
Old 01-10-2006   #4 (permalink)
Rob Relyea [MSFT]
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



Closed Thread

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








Vistax64.com 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 2005-2008

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 47 48 49 50