如何使WPF Toolkit图表扩展以适应内容?

问题描述 投票:0回答:1

我正在尝试从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>
c# wpf charts wpftoolkit
1个回答
1
投票

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

摆脱任何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没有调整其孩子的大小。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.