![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | FrameworkTemplate.LoadContent vs bindings Hi, I have a ControlTemplate that I want to use to generate Control instances. I've managed to do it successfully with the LoadContent() method: Control c = ( Control )controlTemplate.LoadContent(); The only problem with this is that the bindings that are defined in my ControlTemplate don't seem to be propagated to the generated Control instance... Is there another way of creating a Control from a ControlTemplate that would work with bindings? Or is there a way to transfer the bindings manually after LoadContent() has been called? Thanks! Pascal |
| | #2 (permalink) |
| Guest | Re: FrameworkTemplate.LoadContent vs bindings > The only problem with this is that the bindings that are defined in my > ControlTemplate don't seem to be propagated to the generated Control > instance... Can you elaborate? Thanks. -- -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 "Pascal Bourque" <bourquep@xceedsoft.com> wrote in message news:eVXgnJsTGHA.1160@TK2MSFTNGP09.phx.gbl... > Hi, > > I have a ControlTemplate that I want to use to generate Control instances. > I've managed to do it successfully with the LoadContent() method: > > Control c = ( Control )controlTemplate.LoadContent(); > > The only problem with this is that the bindings that are defined in my > ControlTemplate don't seem to be propagated to the generated Control > instance... > > Is there another way of creating a Control from a ControlTemplate that > would work with bindings? Or is there a way to transfer the bindings > manually after LoadContent() has been called? > > Thanks! > > Pascal |
| | #3 (permalink) |
| Guest | Re: FrameworkTemplate.LoadContent vs bindings Here's a simple repro. When you click on the button, I locate the ControlTemplate, generate a Control from this template (via LoadContent), set its DataContext and add it to the StackPanel. The binding declared in the ControlTemplate is not propagated to the Control instance. XAML: <Window x:Class="ControlTemplateBinding.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="ControlTemplateBinding" > <Window.Resources> <ControlTemplate x:Key="myTemplate"> <TextBox Text="{Binding Path=Text,UpdateSourceTrigger=PropertyChanged}" /> </ControlTemplate> </Window.Resources> <StackPanel x:Name="stackPanel"> <TextBlock x:Name="dataSource" Text="This TextBlock.Text is bound to the following TextBox.Text" /> <TextBox DataContext="{Binding ElementName=dataSource}" Text="{Binding Path=Text,UpdateSourceTrigger=PropertyChanged}" /> <Button Click="buttonClicked" Content="Click here to create a TextBox from a ControlTemplate" /> </StackPanel> </Window> CODE BEHIND: private void buttonClicked( object sender, RoutedEventArgs e ) { ControlTemplate template = ( ControlTemplate )this.FindResource( "myTemplate" ); Control control = ( Control )template.LoadContent(); control.DataContext = this.dataSource; this.stackPanel.Children.Add( control ); } Hope this helps clarify what I'm trying to do... Thanks! Pascal Nick Kramer [MSFT] wrote: >> The only problem with this is that the bindings that are defined in my >> ControlTemplate don't seem to be propagated to the generated Control >> instance... > > Can you elaborate? Thanks. > |
| | #4 (permalink) |
| Guest | Re: FrameworkTemplate.LoadContent vs bindings Hi, I noticed an extremelly similar behavior to what you observed... However, in my case, its the Markup Expression "{x:Static expr }" which seems not to be propagated... In my case, I want to generate UI Elements based on a template from within a custom control... I created a DP to hold the "ControlTemplate" for those elements and set the Control Template from within the XAML using my custom control... I want my custom control to generate the required UI Elements during the layout phase so in my MeasureOverride(), I create the appropriate UIElements using the same: UIElement _element = SeparatorTemplate.LoadContent(); where SeparatorTemplate is my CLR accessor for the ControlTemplate's DP... This generates the tree for the UIElement just fine, however, the UI Element which text was set using the x:Static markup expression is blank... The markup expression is valid since I can use the same in different context just fine... Any ideas or suggestions? |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bindings to online: how to change them with network conditions | Craig Kelly | Avalon | 0 | 03-06-2007 02:31 PM |
| Unix-like key bindings? | =?Utf-8?B?cm5pa2FuZGVy?= | PowerShell | 1 | 08-27-2006 09:54 PM |
| Adapters and Bindings in Vista beta 2 | scott | Vista networking & sharing | 3 | 05-29-2006 11:07 AM |