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 - Problems with Dependency Properties and composite controls

 
 
Old 04-07-2006   #1 (permalink)
Rickard Eklind


 
 

Problems with Dependency Properties and composite controls

Hi!

I have crated a composite control with a Dependency Property. When I try to
bind my Dependency Property to any other property I do not get it to work. It
is probably some sort of namespace problem, but I have no idea how to solve
it. Does anybody know?
I am using the Feb CTP

Here is my composite control

<Grid x:Class="TestBinding.MyTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<TextBox Name="InternalTextBox" Text="Test"/>

</Grid>

namespace TestBinding
{
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>

public partial class MyTextBox : Grid
{
public MyTextBox()
{
InitializeComponent();
}
public override void EndInit()
{
base.EndInit();
InternalTextBox.GotFocus += new
RoutedEventHandler(InternalTextBox_GotFocus);
}

void InternalTextBox_GotFocus(object sender, RoutedEventArgs e)
{
int MyValue = this.MyInteger;
}

public int MyInteger
{
get { return (int)GetValue(MyIntegerProperty); }
set { SetValue(MyIntegerProperty, value); }
}

// Using a DependencyProperty as the backing store for MyInteger.
This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyIntegerProperty =
DependencyProperty.Register("MyInteger", typeof(int),
typeof(MyTextBox), new UIPropertyMetadata(0));
}
}


and here is the actual bindin code in my Window. It is the local:MyTextBox
that I have problems with.

<Window x:Class="TestBinding.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestBinding"

Title="TestBinding" Height="300" Width="300"
>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<TextBox Name="MinText" Grid.Column="0" MaxLength="100">Test</TextBox>
<TextBox Grid.Column="1" Text="{Binding ElementName=MinText,
Path=MaxLength}"/>
<local:MyTextBox Grid.Column="2" x:Name="pelle" MyInteger="{Binding
ElementName=MinText, Path=MaxLength}" />
</Grid>
</Window>






My System SpecsSystem Spec
Old 04-10-2006   #2 (permalink)
Nick Kramer [MSFT]


 
 

Re: Problems with Dependency Properties and composite controls

When you say it doesn't work, what does it do? Is it solved by putting
"local:" in front of MyInteger="{Binding ...}" ?

-Nick Kramer [MSFT]

---
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"Rickard Eklind" <Rickard Eklind@discussions.microsoft.com> wrote in message
newsA5CD3A9-D0C0-4425-BBB3-207CFEA14FA3@microsoft.com...
> Hi!
>
> I have crated a composite control with a Dependency Property. When I try
> to
> bind my Dependency Property to any other property I do not get it to work.
> It
> is probably some sort of namespace problem, but I have no idea how to
> solve
> it. Does anybody know?
> I am using the Feb CTP
>
> Here is my composite control
>
> <Grid x:Class="TestBinding.MyTextBox"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
>
> <TextBox Name="InternalTextBox" Text="Test"/>
>
> </Grid>
>
> namespace TestBinding
> {
> /// <summary>
> /// Interaction logic for UserControl1.xaml
> /// </summary>
>
> public partial class MyTextBox : Grid
> {
> public MyTextBox()
> {
> InitializeComponent();
> }
> public override void EndInit()
> {
> base.EndInit();
> InternalTextBox.GotFocus += new
> RoutedEventHandler(InternalTextBox_GotFocus);
> }
>
> void InternalTextBox_GotFocus(object sender, RoutedEventArgs e)
> {
> int MyValue = this.MyInteger;
> }
>
> public int MyInteger
> {
> get { return (int)GetValue(MyIntegerProperty); }
> set { SetValue(MyIntegerProperty, value); }
> }
>
> // Using a DependencyProperty as the backing store for MyInteger.
> This enables animation, styling, binding, etc...
> public static readonly DependencyProperty MyIntegerProperty =
> DependencyProperty.Register("MyInteger", typeof(int),
> typeof(MyTextBox), new UIPropertyMetadata(0));
> }
> }
>
>
> and here is the actual bindin code in my Window. It is the local:MyTextBox
> that I have problems with.
>
> <Window x:Class="TestBinding.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> xmlns:local="clr-namespace:TestBinding"
>
> Title="TestBinding" Height="300" Width="300"
> >

> <Grid>
> <Grid.ColumnDefinitions>
> <ColumnDefinition />
> <ColumnDefinition />
> <ColumnDefinition />
> </Grid.ColumnDefinitions>
>
> <TextBox Name="MinText" Grid.Column="0"
> MaxLength="100">Test</TextBox>
> <TextBox Grid.Column="1" Text="{Binding ElementName=MinText,
> Path=MaxLength}"/>
> <local:MyTextBox Grid.Column="2" x:Name="pelle" MyInteger="{Binding
> ElementName=MinText, Path=MaxLength}" />
> </Grid>
> </Window>
>
>
>
>
>



My System SpecsSystem Spec
Old 04-11-2006   #3 (permalink)
Rickard Eklind


 
 

Re: Problems with Dependency Properties and composite controls

Thanks for your answer Nick. But I still do not get it to work.
When I say it does not worka I mean: The application does run, but when I
set focus on my internal textbox and fetching the value on the dependency
property
int MyValue = this.MyInteger;
the value is 0, and the intentiion was that it should be 100 because of the
binding.

I have tried this
<local:MyTextBox Grid.Column="2" x:Name="pelle" local:MyInteger="{Binding>
ElementName=MinText, Path=MaxLength}" />
in the xaml code but it it does not get any better (or worse)

Regards
Rickard Eklind

"Nick Kramer [MSFT]" wrote:

> When you say it doesn't work, what does it do? Is it solved by putting
> "local:" in front of MyInteger="{Binding ...}" ?
>
> -Nick Kramer [MSFT]
>
> ---
> This posting is provided "AS IS" with no warranties, and confers no rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
>
> "Rickard Eklind" <Rickard Eklind@discussions.microsoft.com> wrote in message
> newsA5CD3A9-D0C0-4425-BBB3-207CFEA14FA3@microsoft.com...
> > Hi!
> >
> > I have crated a composite control with a Dependency Property. When I try
> > to
> > bind my Dependency Property to any other property I do not get it to work.
> > It
> > is probably some sort of namespace problem, but I have no idea how to
> > solve
> > it. Does anybody know?
> > I am using the Feb CTP
> >
> > Here is my composite control
> >
> > <Grid x:Class="TestBinding.MyTextBox"
> > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
> >
> > <TextBox Name="InternalTextBox" Text="Test"/>
> >
> > </Grid>
> >
> > namespace TestBinding
> > {
> > /// <summary>
> > /// Interaction logic for UserControl1.xaml
> > /// </summary>
> >
> > public partial class MyTextBox : Grid
> > {
> > public MyTextBox()
> > {
> > InitializeComponent();
> > }
> > public override void EndInit()
> > {
> > base.EndInit();
> > InternalTextBox.GotFocus += new
> > RoutedEventHandler(InternalTextBox_GotFocus);
> > }
> >
> > void InternalTextBox_GotFocus(object sender, RoutedEventArgs e)
> > {
> > int MyValue = this.MyInteger;
> > }
> >
> > public int MyInteger
> > {
> > get { return (int)GetValue(MyIntegerProperty); }
> > set { SetValue(MyIntegerProperty, value); }
> > }
> >
> > // Using a DependencyProperty as the backing store for MyInteger.
> > This enables animation, styling, binding, etc...
> > public static readonly DependencyProperty MyIntegerProperty =
> > DependencyProperty.Register("MyInteger", typeof(int),
> > typeof(MyTextBox), new UIPropertyMetadata(0));
> > }
> > }
> >
> >
> > and here is the actual bindin code in my Window. It is the local:MyTextBox
> > that I have problems with.
> >
> > <Window x:Class="TestBinding.Window1"
> > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> > xmlns:local="clr-namespace:TestBinding"
> >
> > Title="TestBinding" Height="300" Width="300"
> > >

> > <Grid>
> > <Grid.ColumnDefinitions>
> > <ColumnDefinition />
> > <ColumnDefinition />
> > <ColumnDefinition />
> > </Grid.ColumnDefinitions>
> >
> > <TextBox Name="MinText" Grid.Column="0"
> > MaxLength="100">Test</TextBox>
> > <TextBox Grid.Column="1" Text="{Binding ElementName=MinText,
> > Path=MaxLength}"/>
> > <local:MyTextBox Grid.Column="2" x:Name="pelle" MyInteger="{Binding
> > ElementName=MinText, Path=MaxLength}" />
> > </Grid>
> > </Window>
> >
> >
> >
> >
> >

>
>
>

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Problems with Parental Controls General Discussion
problems w/ properties and previews Media Center
HP7750n problems importing composite video Vista music pictures video


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