相关疑难解决方法(0)

自动高度与MaxHeight结合使用

我在设置以下xaml布局时遇到问题:

RowHeightAuto.xaml

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="GridMaxHeight.RowHeightAuto"
    Title="RowHeightAuto" WindowState="Maximized">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition Height="Auto" MaxHeight="200" />
    </Grid.RowDefinitions>

    <StackPanel Background="LightGray" Grid.Row="0"></StackPanel>
    <DataGrid Name="DataGrid1" Grid.Row="1" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

DataGrid1控件未显示任何定义了大量列和行的滚动条.当我用高度="*"替换高度="自动"时,一切都有效,而水平和垂直滚动条看起来像预期的那样.

当我直接在DataGrid1声明MaxHeight时它也可以工作,但这并不是我想要的.

这是一个bug控件,即childcontrol在设置Height ="Auto"时忽略了最大高度,或者我是否可能做错了?使用ListBox/ListView等可以重现相同的行为,也可以使用ComponentOne,Telerik等第三方控件...

如果这是一个错误 - 你知道一个解决方法或有其他提示吗?

这是我如何设置DataGrid的ItemsSource的代码.RowHeightAuto.xaml.cs

public partial class RowHeightAuto : Window
{
    private readonly DateTime _start;

    public RowHeightAuto()
    {
        InitializeComponent();

        DataGrid1.ItemsSource = GetTestData();

        _start = DateTime.Now;
        Dispatcher.BeginInvoke(new Action(() => MessageBox.Show((DateTime.Now - _start).TotalSeconds.ToString(CultureInfo.InvariantCulture))), DispatcherPriority.ContextIdle, null);
    }

    public static List<TestData> GetTestData()
    {
        const int maxCols = 501;
        const int maxRows = 300;

        var testDatas …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

16
推荐指数
1
解决办法
2万
查看次数

DevExpress.Wpf.Grid.InfiniteGridSizeException未处理

使用DevExpress时,我看到此错误:

DevExpress.Wpf.Grid.InfiniteGridSizeException未处理Message ="默认情况下,不允许无限网格高度,因为所有网格行都将被渲染,因此网格将非常缓慢.要解决此问题,您应该将网格放入将为网格提供有限高度的容器,或者您应该手动指定网格的Height或MaxHeight.请注意,您还可以通过将GridControl.AllowInfiniteGridSize静态属性设置为True来避免此异常,但在这种情况下,网格将运行缓慢".

.net c# wpf xaml devexpress

3
推荐指数
2
解决办法
2492
查看次数

堆栈面板的水平滚动不起作用

我尝试创建一个可滚动的水平 StackPanel 但我没有成功...

目前,我的 StackPanel 的auto宽度(问题可能出在这里)包含一些项目,例如grids.

现在,如果我的所有网格在 StackPanel 中都不可见(宽度太短),我将无法滚动。我已经尝试将 StackPanel 放在 a 中,ScrollViewer但它也不起作用。

我怎样才能解决这个问题?

编辑这里是我的代码:

    <StackPanel Height="85" Margin="0,0,200,15" VerticalAlignment="Bottom">
        <ScrollViewer HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Left" Height="85" CanContentScroll="True">
            <StackPanel x:Name="Film" Height="85" Width="Auto" Margin="0,0,0,0" Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Visible" CanHorizontallyScroll="True" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="True" d:LayoutOverrides="TopPosition, BottomPosition">
                <StackPanel.Background>
                    <SolidColorBrush Color="{DynamicResource ButtonBackground}"/>
                </StackPanel.Background>
                <Grid Width="100" Background="Red"/>
                <Grid Width="100" Background="#FFFF0051"/>
                <Grid Width="100" Background="#FFB900FF"/>
                <Grid Width="100" Background="#FF002EFF"/>
                <Grid Width="100" Background="#FF00FFDC"/>
                <Grid Width="100" Background="#FF51FF00"/>
                <Grid Width="100" Background="Red"/>
            </StackPanel>
        </ScrollViewer>
    </StackPanel>
Run Code Online (Sandbox Code Playgroud)

.net c# wpf scroll stackpanel

3
推荐指数
1
解决办法
2504
查看次数

标签 统计

c# ×3

wpf ×3

.net ×2

xaml ×2

devexpress ×1

scroll ×1

stackpanel ×1