代码之家  ›  专栏  ›  技术社区  ›  ChrisUK

如何使WPF工具包图表扩展以适应内容?

  •  0
  • ChrisUK  · 技术社区  · 6 年前

    我正在尝试创建一些条形图 DotNetProjects.Wpf.Toolkit 它显示一些数据总计,尽管数据可以在运行时更改。问题是,我不能让图表适应内容的大小-我总是需要提供一个固定的值(和设置 Height="Auto" 不起作用),但我不知道跑步时需要多大尺寸。我该怎么做才能使图表符合内容而不是相反?

    我的XAML代码如下:

    <Window
            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:local="clr-namespace:Movie_Vault"
            xmlns:Controls="clr-namespace:System.Windows.Controls;assembly=DotNetProjects.Layout.Toolkit" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="Movie_Vault.frmStatistics"
            mc:Ignorable="d"
            Title="frmStatistics" Style="{StaticResource RoundedFormStyle}" WindowStartupLocation="CenterOwner">
        <Border Style="{StaticResource WindowBorderStyle}">
            <DockPanel x:Name="OuterPanel" >
                <Border Style="{StaticResource PanelBorderStyle}" DockPanel.Dock="Top">
                    <DockPanel x:Name="TopPanel" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                        <Image Height="16" Margin="8,4,8,4" Source="Images/process.png"/>
                        <TextBlock Style="{StaticResource MediumFont}"><Run Text="Statistics"/></TextBlock>
                        <DockPanel DockPanel.Dock="Right" HorizontalAlignment="Right" VerticalAlignment="Center">
                            <Button x:Name="btnClose" Content="X" Style="{StaticResource MicroButtonStyle}" Margin="0,0,8,0" Click="btnClose_Click"/>
                        </DockPanel>
                    </DockPanel>
                </Border>
                <Border Style="{StaticResource PanelBorderStyle}" DockPanel.Dock="Left" Margin="0,8,0,0">
                    <DockPanel VerticalAlignment="Top"  >
                        <ScrollViewer VerticalScrollBarVisibility="Auto" Height="400" Width="500">
                            <Grid Name="panelTopGenres">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="Auto" />
                                </Grid.RowDefinitions>
                                <toolkit:Chart Name="chartTopGenres" Title="Top Genres" VerticalAlignment="Top" 
                       Margin="16,16,16,8" Padding="8" Background="White" >
                                    <toolkit:BarSeries DependentValuePath="Value" IndependentValuePath="Key" 
                               ItemsSource="{Binding}" 
                               IsSelectionEnabled="False" Background="White"/>
                                </toolkit:Chart>
                                <Button Grid.Row="1" x:Name="btnTopGenresToggle" Style="{StaticResource SmallButtonStyle}" 
                Content="Show All Genres" Width="120" 
                Margin="16,0,4,4" HorizontalAlignment="Left" Click="btnToggle_Click" />
                            </Grid>
                        </ScrollViewer>
                    </DockPanel>
                </Border>
            </DockPanel>
        </Border>
    </Window>
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   mm8    6 年前

    我该怎么做才能使图表符合内容而不是相反?

    摆脱任何 StackPanels :

    <Grid Name="panelTopGenres">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <toolkit:Chart Name="chartTopGenres" Title="Top Genres" VerticalAlignment="Top" 
                       Margin="16,16,16,8" Padding="8" Background="White" >
            <toolkit:BarSeries DependentValuePath="Value" IndependentValuePath="Key" 
                               ItemsSource="{Binding}" 
                               IsSelectionEnabled="False" Background="White"/>
        </toolkit:Chart>
        <Button Grid.Row="1" x:Name="btnTopGenresToggle" Style="{StaticResource SmallButtonStyle}" 
                Content="Show All Genres" Width="120" 
                Margin="16,0,4,4" HorizontalAlignment="Left" Click="btnToggle_Click" />
    </Grid>
    

    StackPanel 不调整其子级的大小。