类似手风琴的特殊控制

发布于 2024-11-27 06:01:58 字数 2691 浏览 1 评论 0原文

我在这里放置了一个示例链接: http://activeden.net/item/xml-horizo​​ntal-vertical-accordion-banner-rotator/full_screen_preview/127714?ref=premiumtemplates

我尝试实现类似的东西(但更基本)与 WPF。 不是飞行文字的东西,只有基本的导航理念。 我尝试使用一些扩展器控件和堆栈面板来构建它。 我的想法是:

<ItemsControl Grid.Row="1" IsTabStop="False" ItemsSource="{Binding Path=tabs,Mode=OneWay}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <ContentPresenter  Content="{Binding}" />                    
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Vertical" />               
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>

我使用 MVVM,因此还应用了一个模板:

   <DataTemplate DataType="{x:Type vm:TabulatorViewModel}">
    <Expander  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExpandDirection="{Binding .direction,Mode=OneWay}" IsExpanded="{Binding .isExpanded,Mode=TwoWay}"  Header="{Binding .header,Mode=OneWay}" >
        <Expander.Style>
              <Style TargetType="{x:Type Control}">

                <Setter Property="Template" Value="{StaticResource HorizontalExpanderRight}" />

                <Style.Triggers>

                    <DataTrigger Binding="{Binding .direction}" Value="Left">

                        <Setter Property="Template" Value="{StaticResource HorizontalExpanderLeft}" />

                    </DataTrigger>

                </Style.Triggers>

            </Style>
        </Expander.Style>

        <StackPanel>
            <Label Content="{Binding .seitenInhalt.Header,Mode=OneWay}"></Label>

        <TextBox Text="{Binding .seitenInhalt.Inhalt,Mode=OneWay}"></TextBox>
            <Button Content="zurück" Command="{Binding .seitenInhalt.MovePreviousCommand}" />
            <Button Content="vor" Command="{Binding .seitenInhalt.MoveNextCommand}"/>                 

        </StackPanel>
    </Expander>

</DataTemplate>

所以,这是有效的,至少是这样。

我当前项目的两个屏幕截图来解释问题: 由于信誉点而无法发布图片。

所有项目一起应使用堆栈面板的完整宽度,而不是如图所示。由于信誉点而无法发布图片。

所有项目都应使用完整宽度,但一个展开的项目应具有比其余项目更大的宽度。如图所示,但折叠的项目应使用剩余空间,每个项目以相同的量填充间隙)

任何帮助都会很好,我希望能够理解我的目标/问题。

I have put an example link in here:
http://activeden.net/item/xml-horizontal-vertical-accordion-banner-rotator/full_screen_preview/127714?ref=premiumtemplates

I try to achieve something similar (but far more basic) with WPF.
Not the flying text stuff, only the basic navigation idea.
I tried to build it with some expander controls and a stackpanel.
What I came up with is this:

<ItemsControl Grid.Row="1" IsTabStop="False" ItemsSource="{Binding Path=tabs,Mode=OneWay}">
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <ContentPresenter  Content="{Binding}" />                    
            </DataTemplate>
        </ItemsControl.ItemTemplate>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Orientation="Vertical" />               
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>

I use MVVM, so there is also a template which is applied:

   <DataTemplate DataType="{x:Type vm:TabulatorViewModel}">
    <Expander  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ExpandDirection="{Binding .direction,Mode=OneWay}" IsExpanded="{Binding .isExpanded,Mode=TwoWay}"  Header="{Binding .header,Mode=OneWay}" >
        <Expander.Style>
              <Style TargetType="{x:Type Control}">

                <Setter Property="Template" Value="{StaticResource HorizontalExpanderRight}" />

                <Style.Triggers>

                    <DataTrigger Binding="{Binding .direction}" Value="Left">

                        <Setter Property="Template" Value="{StaticResource HorizontalExpanderLeft}" />

                    </DataTrigger>

                </Style.Triggers>

            </Style>
        </Expander.Style>

        <StackPanel>
            <Label Content="{Binding .seitenInhalt.Header,Mode=OneWay}"></Label>

        <TextBox Text="{Binding .seitenInhalt.Inhalt,Mode=OneWay}"></TextBox>
            <Button Content="zurück" Command="{Binding .seitenInhalt.MovePreviousCommand}" />
            <Button Content="vor" Command="{Binding .seitenInhalt.MoveNextCommand}"/>                 

        </StackPanel>
    </Expander>

</DataTemplate>

So, this is working, at least kind of.

two screenshots from my current project to explain the issues:
Could not post picture because of reputation points.

All Items together should use the complete width of the stackpanel, not like in the picture. Could not post picture because of reputation points.

All items should use the complete width, but the one expanded item should have a bigger width then the rest. As on the picture, but the collapsed items should use the remaining space, each by the same amount filling the gap)

Any help would be great, I hope it is possible to understand my goal / issues.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

友谊不毕业 2024-12-04 06:01:58

我认为您想要使用的是 UniformGridPanel 或 WrapPanel,它将使用可用的完整宽度,而不是使用尽可能最小宽度的 StackPanel。面板概述位于此处

I think what you want to use is a UniformGridPanel or WrapPanel, which will use the full width available, rather than a StackPanel which is made to use the minimum width possible. The panel overview is here.

小…楫夜泊 2024-12-04 06:01:58

您可能需要使用 Grid,并将列/行的 Height/Width 设置为 *如果该项目已展开,则为“自动”,否则为“自动”。

另外,如果您在 ItemsControl 中使用 Grid,则需要设置 Grid.Row/Grid.ColumnWidth/ ContentPresenter 上的 Height 属性,而不是 ItemTemplate,因为 ItemsControl 中的 ItemTemplate 始终包装在 ContentPresenter 中。

You'll probably want to use a Grid with the Height/Width of the Columns/Rows set to * if the item is Expanded, or Auto if not.

Also, if you're using a Grid in an ItemsControl, you need to set the Grid.Row/Grid.Column, and Width/Height properties on the ContentPresenter, not the ItemTemplate since the ItemTemplate in a ItemsControl is always wrapped in a ContentPresenter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文