0

我在一个网格中有两个 ListBox。ListBox ItemsPanelTemplate 设置为“WrapPanel”。我期待看到两个单独的行,但只看到 1。我对 xaml 很陌生。您的帮助将不胜感激。谢谢。

<navigation:Page
x:Class="BusMasterControl.Home" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" 
xmlns:ds="clr-namespace:BusMasterControl.Web"
xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
xmlns:Controls="clr-namespace:BusMasterControl.Controls" 
xmlns:converters="clr-namespace:BusMasterControl.Controls.Converters"
mc:Ignorable="d" 
d:DesignWidth="640" 
d:DesignHeight="480" 
Style="{StaticResource PageStyle}">

<UserControl.Resources>
    <converters:UriToMachineNameConverter x:Key="uriToMachineNameConverter" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot" VerticalAlignment="Top" HorizontalAlignment="Left" ShowGridLines="True">
    <Grid.ColumnDefinitions>
        <ColumnDefinition />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>

    <riaControls:DomainDataSource Name="busMasterControlDomainDataSource2" LoadSize="500" QueryName="GetResourceByDomainAndUriFilter" AutoLoad="True">
        <riaControls:DomainDataSource.DomainContext>
            <ds:BusMasterControlDomainContext />
        </riaControls:DomainDataSource.DomainContext>
        <riaControls:DomainDataSource.QueryParameters>
            <riaControls:Parameter ParameterName="domain" Value="//bus.mydomain.com" />
            <riaControls:Parameter ParameterName="uriFilter" Value="red" />
        </riaControls:DomainDataSource.QueryParameters>

        <riaControls:DomainDataSource.SortDescriptors>
            <riaControls:SortDescriptor PropertyPath="resourceId" Direction="Ascending" />
        </riaControls:DomainDataSource.SortDescriptors>
    </riaControls:DomainDataSource>

    <riaControls:DomainDataSource Name="busMasterControlDomainDataSource" LoadSize="500" QueryName="GetResourceByDomainAndUriFilter" AutoLoad="True">
        <riaControls:DomainDataSource.DomainContext>
            <ds:BusMasterControlDomainContext />
        </riaControls:DomainDataSource.DomainContext>
        <riaControls:DomainDataSource.QueryParameters>
            <riaControls:Parameter ParameterName="domain" Value="//bus.test.mydomain.com" />
            <riaControls:Parameter ParameterName="uriFilter" Value="red" />
        </riaControls:DomainDataSource.QueryParameters>
        <riaControls:DomainDataSource.SortDescriptors>
            <riaControls:SortDescriptor PropertyPath="resourceId" Direction="Ascending" />
        </riaControls:DomainDataSource.SortDescriptors>
    </riaControls:DomainDataSource>

    <ListBox Name="machines2" BorderThickness="0" ItemsSource="{Binding Data, ElementName=busMasterControlDomainDataSource2}"  ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.RowSpan="1">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Controls:BusBench 
                   Background="Gray"
                   BorderBrush="Black"
                   BorderThickness="1"
                   Caption="{Binding Path=uri, Converter={StaticResource uriToMachineNameConverter},FallbackValue=Collapsed}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <ListBox Name="machines" BorderThickness="0" ItemsSource="{Binding Data, ElementName=busMasterControlDomainDataSource}"  ScrollViewer.HorizontalScrollBarVisibility="Disabled"  Grid.RowSpan="1">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <toolkit:WrapPanel />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Controls:BusBench 
               Background="Gray"
               BorderBrush="Black"
               BorderThickness="1"
               Caption="{Binding Path=uri, Converter={StaticResource uriToMachineNameConverter},FallbackValue=Collapsed}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

4

1 回答 1

0

我认为您没有指定第一个列表框属于网格行0,第二个属于网格行10Grid.Row附加属性的默认值,因此您无需为第一个列表框指定它。但是对于第二个,您需要将其明确设置为1

<ListBox Name="machines" Grid.Row="1" ... >
  ...
</ListBox>
于 2012-09-21T18:01:11.217 回答