标签: stackpanel

WPF:为什么所有对网格控制的热爱?

看到WPF应用程序的各种示例我已经看到Grid几乎任何东西都使用该控件,即使是只有1列或行的最简单的东西.

此外,WPF模板以空网格开头.

对我来说,使用StackPanelDockPanel更简洁,更好的维护(想想以后添加一行,不得不向所有其他行添加+1)

为什么Grid更好或我缺少什么?

wpf grid user-interface stackpanel

5
推荐指数
1
解决办法
432
查看次数

VirtualizingStackPanel不起作用

我有以下ListBox:

<ScrollViewer>
    <!--Spec Definitions-->
    <ListBox DataContext="{Binding SpecPackageSpecGroupListViewModel}" 
         VirtualizingStackPanel.IsVirtualizing="True" 
         VirtualizingStackPanel.VirtualizationMode="Recycling" 
         ScrollViewer.IsDeferredScrollingEnabled="True"
         ItemContainerStyle="{StaticResource SpecPackageSpecGroupListBoxStyle}" 
         ItemsSource="{Binding SortedChildren}" 
         Background="Transparent"
         BorderThickness="0" SelectionMode="Extended"
         Margin="5,5,5,5">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Controls:SpecPackageSpecGroupControl/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

这个列表框应该容纳〜1000个项目,但是复杂的项目.我希望它能与VirtualizingStackPanel一起使用,所以我将可视化XAML配置设置为:

VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" 
Run Code Online (Sandbox Code Playgroud)

我的问题是我认为它不起作用 - 首先 - 加载~700项需要很长时间,其次,当我在控制构造函数上遇到断点时 - 我可以看到它被调用700次:

public static int Counter = 0;

public SpecPackageSpecGroupControl()
{
    InitializeComponent();

    Counter++;
    if (Counter%100 == 0)
        Console.WriteLine("Hi");
}
Run Code Online (Sandbox Code Playgroud)

我在Console.WriteLine("Hi")上断点,我可以看到静态计数器达到了700.

所以基本上是创建UIElements,尽管这是一种虚拟模式.

我误解了虚拟化模式,还是我做错了什么?

wpf stackpanel virtualizingstackpanel

5
推荐指数
1
解决办法
3072
查看次数

堆栈面板内的图像未显示

我在 gridview 单元格内动态创建 stackpanel 并在 stackpanel 内放置一个图像控件,但在窗口上只有空白空间,
这里的图像不是我在做什么

StackPanel Stkpnl = new StackPanel();

Image BgImg = new Image();
BitmapImage Img = new BitmapImage(new Uri(
    "Images/cellbg.png", UriKind.Relative));
BgImg.Source = Img ;

Stkpnl.Children.Add(BgImg );
Run Code Online (Sandbox Code Playgroud)

wpf stackpanel c#-4.0

5
推荐指数
1
解决办法
2172
查看次数

在 DockPanel 中填充 StackPanel

这应该很简单:如何在 DockPanel 内拉伸 StackPanel,以便它填充整个父级的内容并保持其 Horizo​​ntalAlignment?

例子:

<DockPanel LastChildFill="True">
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Background="Yellow">
        <Button Height="30">Button1</Button>
        <Button Height="30">Button2</Button>
    </StackPanel>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)

在此示例中,StackPanel 的宽度与两个按钮的组合宽度相同(此处的背景为黄色),但 DockPanel 中的剩余空间保持白色。看起来 LastChildFille 属性在我的示例中不起作用。

c# wpf stackpanel dockpanel

5
推荐指数
1
解决办法
5136
查看次数

为Stack Panel中的控件赋予相同的宽度

我需要RadChart在水平方向内有两个s,StackPanel并希望两个图表的宽度相等.我不想给图表的宽度明确的长度.这可以通过使用Grid控件轻松实现,但我的场景需要a StackPanel.

silverlight wpf stackpanel windows-8

5
推荐指数
2
解决办法
4024
查看次数

如何在Windows Phone 8的堆栈面板中将一个组件对齐到左侧和另一个组件

我想在窗口电话8中水平对齐的堆叠面板中安排两个组件,一个在左边,另一个在右边.

我需要左对齐的组件应该在页面的左侧,右对齐的组件应该在页面的右侧.这两个组成部分之间应该存在差距.

左对齐组件是静态的,右对齐组件是动态的.对于静态组件,我为动态组件设置了width = auto和剩余空间.

以下是我的代码.

<Border x:Name="DataBorder" Grid.Row="1" BorderBrush="Gray" CornerRadius="5,5,5,5" BorderThickness="2,2,2,2" Margin="10,30,10,10">
        <StackPanel x:Name="settingsPanel" Orientation="Vertical">
            <StackPanel x:Name="langPanel" Orientation="Horizontal">
                <TextBlock x:Name="langTextBlock" Text="{Binding Path=LocalizedResources.DefaultLanguageText, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"  Foreground="#FF501F6E" FontWeight="Bold" FontSize="25" Width="Auto"/>

                <Button Content="English" Height="70" HorizontalAlignment="Right" Margin="5,1,0,0" Name="langbutton" VerticalAlignment="Center" MinWidth="160" Foreground="#FF501F6E"  Click="language_Btn_clicked" BorderBrush="{x:Null}">
                    <Button.Background>
                        <ImageBrush Stretch="Fill" ImageSource="Images/blank_button_nav.png" />
                    </Button.Background>
                </Button>

                <!--<Image x:Name="arrow" Stretch="Fill" Margin="0,0,0,0" Source="Images/arrow.png" Height="20"/>-->
            </StackPanel>

            <StackPanel x:Name="pagePanel" Orientation="Horizontal">
                <TextBlock x:Name="pageTextBlock" Text="{Binding Path=LocalizedResources.PerPageText, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"  Foreground="#FF501F6E" FontWeight="Bold" FontSize="25" Width="Auto"/>

                <Button Content="25" Height="70" HorizontalAlignment="Right" Margin="5,1,0,0" …
Run Code Online (Sandbox Code Playgroud)

stackpanel windows-phone-7 windows-phone-8

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

XAML水平Stackpanel滚动

我在滚动浏览器中滚动水平堆栈面板时遇到问题.我正在尝试做的比我的例子更复杂,但在删除变量之后,我想如果我能解决这个问题,我可以解决所有问题.

基本上,当包含水平堆栈面板时,我无法让滚动查看器水平滚动.

以下是XAML示例:

   <ScrollViewer>
        <StackPanel Orientation="Horizontal">
            <Image Source="test.png" Width="400" Height="400"/>
            <Image Source="test.png" Width="400" Height="400"/>
            <Image Source="test.png" Width="400" Height="400"/>
            <Image Source="test.png" Width="400" Height="400"/>
            <Image Source="test.png" Width="400" Height="400"/>
            <Image Source="test.png" Width="400" Height="400"/>
            <Image Source="test.png" Width="400" Height="400"/>
        </StackPanel>
    </ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我只是将方向从水平交换到垂直,它滚动就好了.我已经阅读过多个帖子,堆栈面板有问题可能使它们不适合滚动查看器,所以我也尝试使用网格,但得到相同的结果.

  <ScrollViewer>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="400"/>
                <ColumnDefinition Width="400"/>
                <ColumnDefinition Width="400"/>
                <ColumnDefinition Width="400"/>
                <ColumnDefinition Width="400"/>
                <ColumnDefinition Width="400"/>
            </Grid.ColumnDefinitions>                
            <Image Source="test.png" Width="400" Height="400"  Grid.Column="0"/>
            <Image Source="test.png" Width="400" Height="400"  Grid.Column="1"/>
            <Image Source="test.png" Width="400" Height="400"  Grid.Column="2"/>
            <Image Source="test.png" Width="400" Height="400"  Grid.Column="3"/>
            <Image Source="test.png" Width="400" Height="400"  Grid.Column="4"/>
            <Image Source="test.png" …
Run Code Online (Sandbox Code Playgroud)

xaml stackpanel horizontal-scrolling windows-8 windows-runtime

5
推荐指数
1
解决办法
7554
查看次数

在wpf中更改stackpanel的子索引

我想知道如何在c#代码中更改StackPanel 的子索引.

例如,我想首先显示当前第二个孩子.我在更改索引时需要动画.

我正在使用StackPanel,因为我需要Orientation属性来堆叠所有元素并将它们组合在一起.如果你有更好的想法使用另一个控件,我对此持开放态度.

c# wpf controls stackpanel

4
推荐指数
1
解决办法
4422
查看次数

WPF:样式中的故事板返回"无法在不可变对象实例上设置动画'颜色'."

我有以下XAML:

<UserControl.Resources>
    <SolidColorBrush x:Key="Brush"></SolidColorBrush>

    <Style TargetType="{x:Type StackPanel}" x:Key="ColourChangingStyle">
        <Setter Property="Background" Value="{StaticResource Brush}" />

        <Style.Triggers>
            <DataTrigger Binding="{Binding Path='Stage'}" Value="1">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation Storyboard.Target="{StaticResource Brush}"
                              Storyboard.TargetProperty="Color" From="{StaticResource FirstColor}" To="{StaticResource FinishedColor}" Duration="0:0:10" BeginTime="0:0:0"/>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</UserControl.Resources>

<StackPanel x:Name="InfoPanel" Orientation="Vertical"  Margin="1,2" Style="{DynamicResource ColourChangingStyle}">
 ...
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

我一直得到同样的错误:

无法在不可变对象实例上设置"颜色"动画

这是刷子.我查了一下这个问题,并认为这与将画笔绑定StackPanel到以后无法改变它有关.

有什么方法可以解决这个问题,我完全不知道我的其他相同效果的选项是没有硬编码颜色,并且在代码中执行所有事件.

wpf animation xaml user-controls stackpanel

4
推荐指数
1
解决办法
4316
查看次数

DataGrid中的VirtualizingPanel

我最近开始探索WPF中的数据和UI虚拟化功能,偶然发现了一些奇怪的东西.

我创建了一个DataGrid"s的Virtualizing启用和一个有1,000,000项的列表填充它.这种方法效果非常好而且速度惊人.

<Grid>
    <DataGrid x:Name="employees" VirtualizingPanel.IsVirtualizing="True" 
                                 VirtualizingPanel.IsContainerVirtualizable="True"
                                 VirtualizingPanel.VirtualizationMode="Recycling"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

但是,当我把它嵌入它下载StackPanel超过一分钟直到我得到OutOfMemoryException.我也设置了相同的VirtualizingPanel属性,StackPanel但它没有帮助.

这种行为是故意还是我错过了一些基本的东西?我如何设法在嵌套控件中支持数据虚拟化?

c# wpf datagrid stackpanel virtualizingstackpanel

4
推荐指数
1
解决办法
3518
查看次数