0

結局欲しいもの

同じ外観 (素晴らしいコントロール) を持つアイテムのテーブルですが、次のように異なるテキストが表示されますが、それ以上のものがあります。

_ 3 6
1 4 7
2 5 8
_ _ 9

「_」は何もありません。

私が持っているもの

gridView の境界線を使用した非常に単純な例があり、GridView.ItemTemplate の項目間にスペースがある理由がわかりませんか? ItemHeightとItemWidthに大きな値を設定すると、すべて問題ありません(境界線のフルサイズが表示されます)が、この場合、アイテム間
さらに大きなスペースがあり ます<VariableSizedWrapGrid Orientation="Vertical" Margin="0" ItemHeight="" ItemWidth="" />

私の例の完全なコード


class SomeData
{
    public SomeData(int i)
    {
        Number = i;
    }

    public int Number { get; set; }
}

class SomeModel
{
    public SomeModel(int key)
    {
        Key = key.ToString();
        Items = new List<SomeData>();
    }

    public string Key { get; set; }

    public List<SomeData> Items { get; set; }
}

class ItemPanelVM : BindableBase
{
    public ItemPanelVM()
    {
        var list = new List<SomeModel>();

        for (int i = 0; i < 10; i++)
        {
            list.Add(new SomeModel(i));

            for (int j = 0; j < 10; j++)
            {
                list[i].Items.Add(new SomeData(j));
            }
        }

        SomeGroup = list;
    }


    private List<SomeModel> _someModels;
    public List<SomeModel> SomeGroup
    {
        get { return _someModels; }
        set
        {
            _someModels = value;
            OnPropertyChanged();
        }
    }
}

および xaml スニペット


<UserControl.Resources>

    <CollectionViewSource
        x:Key="simpleViewSource"
        IsSourceGrouped="True"
        Source="{Binding SomeGroup}"
        ItemsPath="Items"
        d:Source="{Binding SomeGroup, Source={d:DesignInstance Type=test:ItemPanelVM, IsDesignTimeCreatable=True}}"/>

</UserControl.Resources>

<Grid DataContext="{Binding}">  
    <GridView SelectionMode="None" IsItemClickEnabled="False" 
              ItemsSource="{Binding Source={StaticResource simpleViewSource}}" 
              HorizontalAlignment="Left" 
              Margin="0">

        <GridView.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </GridView.ItemsPanel>
        <GridView.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <Grid Margin="0" >
                            <TextBlock Text="{Binding Key}" />
                        </Grid>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
                <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                        <VariableSizedWrapGrid Orientation="Vertical" Margin="0"
                                               ItemHeight="30" ItemWidth="30" />
                    </ItemsPanelTemplate>
                </GroupStyle.Panel>
            </GroupStyle>
        </GridView.GroupStyle>
        <GridView.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Border DataContext="{Binding}" Margin="0" Background="Pink" BorderThickness="2" BorderBrush="Brown" Height="30" Width="30">
                        <TextBlock Text="{Binding Number}" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center"/>
                    </Border>
                </Grid>
            </DataTemplate>
        </GridView.ItemTemplate>
    </GridView>
</Grid>

結果

スクリーンショット

質問

なんで?これらのスペースはどこから来たのですか? どうしたらいいのかわからないという話ではありません。何が起こっているのかわからないということです。

PS Google翻訳へのすべての苦情。

4

1 に答える 1

3

の奥深くに埋もれていItemContainerStyleます。コピーを作成します。

ここに画像の説明を入力

次に、スタイルで次の 2 つの要素を検索します。

 <Setter Property="Margin" Value="0,0,2,2"/>
  ...

      <Border x:Name="ContentBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="4">

両方のマージンをゼロに設定すると、スペースが削除されます。スタイルにはハードコードされた Margin 4 の要素がたくさんあることに気付きました。それらの要素のいくつかはさまざまな視覚状態で作用するため、それらも調整する必要があるかもしれません。

于 2013-02-17T04:58:33.477 に答える