![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 news A5CD3A9-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 Specs![]() |
| | #3 (permalink) |
| | 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 > news A5CD3A9-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 Specs![]() |
| 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 | |||