![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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> |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Output not collected from synthetic setter methods | PowerShell | |||
| template with Netsh | Vista networking & sharing | |||