Wpf Xaml Listbox扩展了整个usercontrol
因此,我有一个列表框,显示usercontrol中的一些数据:Wpf Xaml Listbox扩展了整个usercontrol,wpf,xaml,Wpf,Xaml,因此,我有一个列表框,显示usercontrol中的一些数据: <UserControl x:Class="FSBEM.UCs.SomeUC" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid Margin="7,0,9,0"> <Grid.RowDefinitions> &l
<UserControl x:Class="FSBEM.UCs.SomeUC"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<Grid Margin="7,0,9,0">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ListBox x:Name="ListBox"
SelectedValuePath="Id"
ItemsSource="{Binding}"
Margin="0,5,5,5">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock DockPanel.Dock="Right">
<TextBlock.Text>
<MultiBinding StringFormat="{} {0} ">
<Binding Path="Name" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<Button x:Name="Btn_Delete"
Padding="5,0,5,0"
CommandParameter="{Binding}">
<Image Source="/Media/Icons/Delete_Icon.png"
Width="10"
Height="10"/>
</Button>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBox Name="txtBox"
Height="22"
Margin="0,14,5,5"/>
</Grid>
</UserControl>
问题是listbox没有粘到主窗口边框上。。相反,它将整个usercontrol向下延伸到主窗口之外。。我试着设置MaxHeight,但这对我来说不是一个解决方案。我想处理它,当有太多的数据无法显示时,将其粘贴到主窗口边框并显示一个滚动条
更新
这是主窗口的xaml代码:
<Window x:Class="FSBEM.MainWindow"
Height="471.997"
Width="1186.374"
WindowStartupLocation="CenterScreen"
WindowState="Maximized">
<ScrollViewer FlowDirection="RightToLeft"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto">
<Grid x:Name="MainGrid"
FlowDirection="RightToLeft">
<Menu x:Name="menu"
HorizontalAlignment="Stretch"
Height="23"
VerticalAlignment="Top" />
<Grid Name="InnerGrid"
Margin="0,23,0,20" />
</Grid>
</ScrollViewer>
我在“InnerGrid”中显示用户控件好的,我发现了问题,是主窗口中的ScrollBarViewer。这就是为什么列表框可以自由伸展。移除ScrollBarViewer解决了问题。好的,我发现了问题,是主窗口中的ScrollBarViewer。这就是为什么列表框可以自由伸展。删除ScrollBarViewer解决了问题。您是否尝试过将列表框包装到scrollviewer中?是的,我尝试过。它的行为应该是相同的:您能在插入usercontrol的地方显示主xaml吗?问题也可能存在……这真的没有任何意义,因为在您的示例中,
网格
行定义.高度
设置为40
,所以整个列表应该几乎隐藏并缩小为零。您尝试过在scrollviewer中包装列表框吗?是的。它的行为应该是相同的:您能在插入usercontrol的地方显示主xaml吗?问题可能就在那里……这真的没有任何意义,因为在您的示例中,网格
行定义。高度
设置为40
,因此整个列表应该几乎隐藏起来,并缩小为零