![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | RelativeSource=/ParentData in Setter or Template? When I access RelativeSource=/ParentData inside style Setters and Templates I always get null. I can't work out how to rebind the DataContext in these scenarios. For example: <Style x:Key="MyStyle" TargetType="{x:Type Control}"> <Setter Property="DataContext" Value="{Binding RelativeSource=/ParentData}" /> </Style> or: <Setter Property="Template"> <Setter.Value> <ControlTemplate> <Grid DataContext="{Binding RelativeSource=/ParentData}" /> </ControlTemplate> </Setter.Value> </Setter Property="Template"> How can I reference the current context? I'm trying to do this because I need to run the current data context through an IValueConverter. - Doug A complete example follows, drop the DataContext Setter to see the desired result. <?Mapping XmlNamespace="sys" ClrNamespace="System" Assembly="mscorlib"?> <Window x:Class="EventTest.Window1" xmlns="http://schemas.microsoft.com/winfx/avalon/2005" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" xmlns:sys="sys" Title="EventTest" > <Window.Resources> <x:ArrayExtension Type="{x:Type sys:String}" x:Key="Data"> <sys:String>one</sys:String> <sys:String>two</sys:String> <sys:String>three</sys:String> <sys:String>four</sys:String> </x:ArrayExtension> <Style x:Key="MasterDetail" TargetType="{x:Type Control}"> <Setter Property="DataContext" Value="{Binding RelativeSource=/PreviousData}" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <DockPanel> <TextBlock TextBlock.FontSize="30" DockPanel.Dock="Right" Text="{Binding Path=/.}" /> <ListBox ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" /> </DockPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <DockPanel DataContext="{Binding Source={StaticResource Data}}"> <Control Style="{StaticResource MasterDetail}" /> </DockPanel> </Window> |
| | #2 (permalink) |
| Guest | Re: RelativeSource=/ParentData in Setter or Template? Ok, so it looks like I didn't fully understand what ParentData meant. And it would seem there is no RelativeSource directly to the current scope? Instead, the following workaround seems to do what I want. <ControlTemplate> <Grid DataContext="{Binding RelativeSource=/TemplatedParent, Path=DataContext} /> </ControlTemplate> - Doug > When I access RelativeSource=/ParentData inside style Setters and > Templates I always get null. I can't work out how to rebind the > DataContext in these scenarios. |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| RelativeSource PreviousData doesn’t work in ListView? | Sergey Aldoukhov | Avalon | 0 | 06-24-2008 02:05 PM |
| Template folder | cherrybee | Live Mail | 1 | 03-16-2008 07:58 PM |
| Output not collected from synthetic setter methods | Catweazle | PowerShell | 1 | 12-13-2007 01:54 PM |
| Why can't I use TemplateBinding in Setter? | HolaMan | Avalon | 2 | 04-13-2006 01:27 AM |
| Using a StaticResource in a template | Keith Patrick | Avalon | 3 | 02-13-2006 09:10 AM |