2

我对 WPF 很陌生,并且正在努力实现视觉效果 - 我想要一个二维对象网格,其中包含数据驱动的列数。我正在尝试使用具有零代码隐藏的 MVVM。我已经看过这方面的几个帖子,并提出了以下内容:

<UserControl x:Class="Demo.Views.SideBySideStackPanelView"
             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" 
             xmlns:views="clr-namespace:Demo.Views"
             xmlns:viewModels="clr-namespace:Demo.ViewModels"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate x:Key="ColumnTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="400"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*" SharedSizeGroup="TreeView"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*" SharedSizeGroup="DetailView"/>
                </Grid.RowDefinitions>

                <DockPanel Grid.Row="0" LastChildFill="True">
                    <TextBlock Text="{Binding Name}" DockPanel.Dock="Left"/>
                    <Button Command="{Binding Close}" DockPanel.Dock="Right" HorizontalAlignment="Right">
                        <Image Width="10" Height="10" Source="/Demo;component/Images/Close.png" />
                    </Button>
                </DockPanel>

                <views:TreeView Grid.Row="1"/>

                <GridSplitter 
                    ResizeDirection="Rows" 
                    VerticalAlignment="Center"
                    HorizontalAlignment="Stretch"
                    Height="5"
                    Grid.Row="2"
                    Name="sideBySideSplitter"/>

                <views:TreeDetail Grid.Row="2"/>

            </Grid>
        </DataTemplate>
    </UserControl.Resources>

    <Grid d:DataContext="{d:DesignInstance viewModels:MainWindowViewModel}" Grid.IsSharedSizeScope="True">
        <ItemsControl ItemsSource="{Binding PluginItem}" ItemTemplate="{StaticResource ColumnTemplate}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </Grid>
</UserControl>

TreeView 视图是一个基本的绑定 TreeView,而 TreeDetail 视图是一个简单的绑定 Grid。

该控件确实会根据需要或多或少地呈现我的内容,但是当我与列上部的树视图交互时,控件会垂直扩展,而不是在树中显示滚动条。GridSplitter 根本不起作用;事实上,它似乎呈现在细节对象的中间。

我在 TabControl.ContentTemplate 中有一个类似的 DataTemplate,它可以按需要工作。移动 GridSplitter 会导致滚动条在必要时显示在任一侧,打开 TreeView 项会导致滚动条显示在该控件中。

我所追求的是类似 Excel 的演示文稿,其中用户可以使用水平和垂直“拆分器”控制单元格的大小,并且单元格内的用户对象根据需要在单元格内滚动。我现在可以忍受固定大小的列。

我将不胜感激提供的任何帮助。谢谢。

4

0 回答 0