我有下面的XAML代碼:WPF綁定屬性爲另一種元素屬性由元素的name
<Grid KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Background="Transparent" BorderThickness="0,0,0,2" BorderBrush="{StaticResource TabPanelBorderBrush}">
<DockPanel LastChildFill="True">
<Button x:Name="LeftButton" Content="3" DockPanel.Dock="Left" Style="{DynamicResource TabControlButton}"></Button>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Right">
<Button x:Name="RightButton" Content="4" Style="{DynamicResource TabControlButton}"></Button>
<Button x:Name="TabItemsList" Content="L" FontFamily="Segoe UI" Style="{DynamicResource TabControlButton}"></Button>
<Button x:Name="AddTabItem" Content="+" FontFamily="Segoe UI" Style="{DynamicResource TabControlButton}"></Button>
</StackPanel>
<ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden">
<TabPanel x:Name="HeaderPanel" IsItemsHost="True" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1"/>
</ScrollViewer>
</DockPanel>
</Border>
<Border Grid.Row="1" Background="{StaticResource TabControlBackground}"/>
<ContentPresenter Grid.Row="1" Name="PART_SelectedContentHost" ContentSource="SelectedContent"/>
</Grid>
<ListBox x:Name="TabItemsListBox" Width="200" Height="200" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="Collapsed">
<ListBox.Margin>
<Thickness Left="0" Top="{Binding to TabItemsList height}" Right="0" Bottom="20"/>
</ListBox.Margin>
</ListBox>
</Grid>
我要綁定的ListBox
頂級Thickness
(TabItemsListBox)到TabItemsList
的Height
。 我該怎麼做?嘗試:
{Binding ElementName=TabItemsList, Path=Height}
但我的計劃粉碎,當我運行它
嘗試ActualHeight而不是高度 – iulian3000
仍然粉碎... – Ron
頂部是typeof厚度,這就是爲什麼它粉碎,並且你正在綁定一個雙重厚度。也許在一個轉換器的幫助下,你可以將它綁定到頂部 – iulian3000