Xaml 如何在Viewbox中保持对齐和间距
我有一个标签和值的列表。例如(此示例用于说明): 我想能够添加到这个列表,并有文本收缩,使列表将填补可用空间,但不超过它。我还希望能够调整窗口的大小,并有列表填充可用的空间。我尝试使用Viewbox来完成此任务,但以两种不同的方式失败: 1) 我尝试使用一个网格,并用一个Viewbox围绕每个标签和值。这保持了标签和值之间的间距,但标签和值的大小不同。以下是显示播放机信息的用户控件的代码:Xaml 如何在Viewbox中保持对齐和间距,xaml,spacing,viewbox,Xaml,Spacing,Viewbox,我有一个标签和值的列表。例如(此示例用于说明): 我想能够添加到这个列表,并有文本收缩,使列表将填补可用空间,但不超过它。我还希望能够调整窗口的大小,并有列表填充可用的空间。我尝试使用Viewbox来完成此任务,但以两种不同的方式失败: 1) 我尝试使用一个网格,并用一个Viewbox围绕每个标签和值。这保持了标签和值之间的间距,但标签和值的大小不同。以下是显示播放机信息的用户控件的代码: <UserControl x:Class="Viewbox.Player"
<UserControl x:Class="Viewbox.Player"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Viewbox Grid.Column="0">
<TextBlock FontSize="30" Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
</Viewbox>
<Viewbox Grid.Column="1" HorizontalAlignment="Right">
<TextBlock FontSize="30" Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Viewbox>
</Grid>
</UserControl>
结果如下:
2) 我试着用Viewbox包围网格。这是我想要的文本大小,但现在我的间距消失了,每一行都居中了
<UserControl x:Class="Viewbox.Player"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Viewbox>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" FontSize="30" Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" FontSize="30" Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Grid>
</Viewbox>
</UserControl>
我已经围绕这个问题跳了一段时间了。有人能帮我吗
谢谢 我可以通过插入一个空白列来解决这个问题。这将保留对齐方式和字体大小(在一定程度上):
不幸的是,当窗户的尺寸非常高时,它会发生一些故障:
但是,出于我的目的,我可以限制总高度,因此这不是问题。使用边距也没有帮助吗?请同时发布您的xaml。这对我来说没有意义。项目数量可变的列表应顶部对齐。如果项目超出可用空间,则应可滚动。您应该使用普通的ItemsControl或ListBox进行显示。“不同的字体大小是很难看的。”克莱门斯-正如我所说,我的示例只是为了说明。我试着把一个简单的案例归结起来,它代表了我正在努力做的事情。在我的情况下,我绝对不希望列表中有空白。
<UserControl x:Class="Viewbox.Player"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Viewbox>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" FontSize="30" Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" FontSize="30" Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Grid>
</Viewbox>
</UserControl>
<UserControl x:Class="Viewbox.Player"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Viewbox Grid.Column="0">
<TextBlock Margin="5" Text="{Binding Name}" HorizontalAlignment="Left"/>
</Viewbox>
<Viewbox Grid.Column="2">
<TextBlock Margin="5" Text="{Binding Average, StringFormat={}{0:0.000}}" HorizontalAlignment="Right"/>
</Viewbox>
</Grid>
</UserControl>