So i have a style for a treeview that is failing to bind correctly. I have bound height to the graph height property of the user control the style is used in. However, it doesn't find the user control for some unknown reasons. I was hoping someone could shed some light on the issue. Is it forbidden to bind a property of a template to something other than the templated parent? And why can't it find the element just because it is in a style.
From the beginning of the xaml file:
<UserControl
x:Class="WpfExperimental.GraphViewer"
x:Name="graph_viewer"
and then the style:
<Style x:Key="SignalNameTreeViewStyle" TargetType="TreeView">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<ScrollViewer x:Name="SignalNameTreeView_ScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Hidden">
<StackPanel>
<wpfExp:SignalNameBox x:Name="TreeViewTimeTextBox" Grid.Row="0" Grid.Column="0"
Height="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}"
Width="200"
Margin="19,0,0,0"
MainText="Time"
/>
<ItemsPresenter/>
</StackPanel>
</ScrollViewer>
<ControlTemplate.Triggers>
<Trigger Property="ItemsControl.HasItems" Value="False">
<Setter TargetName="TreeViewTimeTextBox"
Property="Visibility"
Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Currently I get data binding errors from this attempt to bind
ystem.Windows.Data Error: 39 : BindingExpression path error: 'GraphHeight' property not found on 'object' ''UserControl' (Name='graph_viewer')'. BindingExpression:Path=GraphHeight; DataItem='UserControl' (Name='graph_viewer'); target element is 'SignalNameBox' (Name='TreeViewTimeTextBox'); target property is 'Height' (type 'Double')
System.Windows.Data Error: 39 : BindingExpression path error: 'GraphHeight' property not found on 'object' ''UserControl' (Name='graph_viewer')'. BindingExpression:Path=GraphHeight; DataItem='UserControl' (Name='graph_viewer'); target element is 'SignalGraphAxis' (Name='signal_axis'); target property is 'GraphHeight' (type 'Int32')
System.Windows.Data Error: 39 : BindingExpression path error: '_SignalDataViewModel' property not found on 'object' ''UserControl' (Name='graph_viewer')'. BindingExpression:Path=_SignalDataViewModel.MaxTimeValue; DataItem='UserControl' (Name='graph_viewer'); target element is 'SignalGraphAxis' (Name='signal_axis'); target property is 'MaxTimeValue' (type 'Int32')
Binding
onTemplateBinding
. It helped? – Anatoliy Nikolaev Jul 12 '13 at 21:39