我有以下xaml:
<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>
Run Code Online (Sandbox Code Playgroud)
我想将ListBox顶部Thickness(TabItemsListBox)绑定到TabItemsList's Height.我怎样才能做到这一点?尝试:
{Binding ElementName=TabItemsList, Path=Height}
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,我的程序会崩溃
我希望它有效,现在我使用multibinding.有了这个,您必须提供4个绑定,否则它将失败,或者您可以进行测试以防止转换器中的任何错误.
XAML:
<ListBox x:Name="TabItemsListBox"
Width="50"
Height="50">
<ListBox.Margin>
<MultiBinding Converter="{StaticResource Converter}">
<MultiBinding.Bindings>
<Binding ElementName="TabItemsListBox"
Path="ActualHeight" />
<Binding ElementName="TabItemsListBox"
Path="ActualHeight" />
<Binding ElementName="TabItemsListBox"
Path="ActualHeight" />
<Binding ElementName="TabItemsListBox"
Path="ActualHeight" />
</MultiBinding.Bindings>
</MultiBinding>
</ListBox.Margin>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
转换器:
public class DoubleToMarginConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var left = (double)values[0];
var top = (double)values[1];
var right = (double)values[2];
var bottom = (double)values[3];
return new Thickness(left, top, right, bottom);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
最困扰我的是我不会通过多重绑定获得智能感知.我也是新手:)
| 归档时间: |
|
| 查看次数: |
17741 次 |
| 最近记录: |