所以,我對於未能成功地進行正確綁定一個TreeView的樣式。 我已經綁定了用戶控件的圖形高度屬性的高度屬性,但是,由於某些未知原因,它找不到用戶控件。我希望有人能夠解釋這個問題。禁止將模板的屬性綁定到除模板父項以外的其他項目嗎?爲什麼它不能僅僅因爲它是一種風格而找到這個元素。WPF綁定風格到另一個控件的屬性
從XAML文件的開頭:
<UserControl
x:Class="WpfExperimental.GraphViewer"
x:Name="graph_viewer"
,然後風格:
<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>
目前我得到的數據,從這種企圖綁定錯誤綁定
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')
嘗試更換''上TemplateBinding' Binding'。它有幫助嗎? –