当没有空间时,自动调整大小的项目控制滚动 [英] Have auto sized itemscontrol scroll when no space remains

查看:76
本文介绍了当没有空间时,自动调整大小的项目控制滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我希望在屏幕不适合的情况下有一个itemscontrol滚动,但要占用尽可能少的空间。



假设我有一个包含3列的网格,第0列中的标签,第1列中的项目控件和第2列中的按钮。我希望标签保留在左侧,按钮为保持左对齐,但即使itemcontrol太大,按钮仍保持在视图中。



我所拥有的是一个itemscontrol,其itemtemplate设置为水平stackpanel并且此itemcontrol包含在scrollviewer中,以便在没有剩余空间时滚动。这有效,如果我将列宽设置为auto,*和auto,但是我希望itemscontrol与其内容一样小,并且按钮要相邻,为了实现这一点,我需要itemscontrol为auto或者按住按钮的列是*。



这个问题是如果我设置按住按钮的列是*我可以对中间列做的是make它是固定宽度或自动,如果设置为自动,滚动条永远不会出现,与堆栈面板有无限大小有关。



这是我到目前为止的代码,我希望我已经清楚地解释了我的要求了吗?



Hi
I wish to have an itemscontrol scroll when it does not fit on the screen but to take as little space as possible.

Let's say I have a grid with 3 columns, a label in column 0, an items control in column 1 and a button in column 2. I wish for the label to remain on the left, and the button to remain left aligned but for the button to remain in view even when the itemscontrol is too big.

what i have is an itemscontrol with its itemtemplate set as a horizontal stackpanel and this itemcontrol is wrapped in a scrollviewer so that it scrolls when there is no space remaining. this works if i set the column width to be auto, * and auto respectively however i wish for the itemscontrol to be as small as its content and for the button to be adjacent, to achieve this I would need itemscontrol to be auto or for the column holding the button to be *.

the problem with this is if i set the column holding the button to be * all i can do to the middle column is make it a fixed width or auto, if set to auto the scrollbar never appears, something to do with stackpanel having infinite size.

Here is the code I have so far, I hope I have explained my requirements clearly?

<Grid>
  <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

            <Label Content = "Blah"
Grid.Column="0"/>

        <ScrollViewer Grid.Column="1"
                      HorizontalScrollBarVisibility="Auto"
                      VerticalScrollBarVisibility="Disabled">
            <ItemsControl ItemsSource="{Binding StringInfos}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Width="300"
                                HorizontalContentAlignment="Stretch">
                            <Button.Content>
                                <Border BorderThickness="1"
                                        BorderBrush="Black">
                                    <Grid Grid.Column="0"
                                          removed="Transparent">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="30" />
                                            <RowDefinition Height="30"/>
                                            <RowDefinition Height="100"/>
                                        </Grid.RowDefinitions>
                                        <Label Content="{Binding Pressure}"
                                               HorizontalAlignment="Center"
                                               Grid.Row="0"/>
                                        <Label Content="{Binding FluidDensity}"
                                               HorizontalAlignment="Center"
                                               Grid.Row="1"/>
                                    </Grid>
                                </Border>
                            </Button.Content>
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <DockPanel  />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>
        </ScrollViewer>

        <Button Grid.Column="2"
                Command="{Binding AddStringInfoCommand}"
                VerticalAlignment="Top"
                Content="Add"/>
    </Grid>

推荐答案

这篇关于当没有空间时,自动调整大小的项目控制滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆