C#Wpf如何使用其中的按钮更改Listviewitem的高度? [英] C# Wpf How to Change Listviewitem's Height Using a Button in it?

查看:101
本文介绍了C#Wpf如何使用其中的按钮更改Listviewitem的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含1个按钮的listview项.Listview项的默认高度为60.

I have listview items that contains 1 button in it. Listview item's default height is 60.

当我单击列表视图项目的按钮时,该行(包含单击的按钮)的高度应更改为100.当我再次单击该按钮时,行的高度应更改为60.

When i click listview item's button, that row(contains the button clicked)'s height should change to 100. When i click that button again row's height should change back to 60.

我真的不知道该怎么实现.

I'm really can't find out how to implement this.

当我单击Row1的详细信息按钮时,Row1的高度应更改为100.如果再次单击它,其高度应更改为60.

When i click Row1's details button, Row1's height should change to 100. If i click it again it's heigth should change back to 60.

我正在向按钮列表项添加按钮,如下所示:

I'm adding buttons to listview items like this :

                 <GridViewColumn >
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>                                  
                               <ButtonName="DetailsButton"Content="Details"FontWeight="Bold"  HorizontalAlignment="Left" Margin="520,35,0,0" VerticalAlignment="Top" Width="75" Height="25">
                               </Button>
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

推荐答案

您可以使用DataTemplate Triggers 来实现相同的目的

you may use DataTemplate Triggers to achieve the same

样本

<GridViewColumn>
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <ToggleButton Name="DetailsButton"
                              Content="Details"
                              FontWeight="Bold"
                              HorizontalAlignment="Left"
                              Margin="520,35,0,0"
                              VerticalAlignment="Top"
                              Width="75"
                              Height="25">
                </ToggleButton>
            </Grid>
            <DataTemplate.Triggers>
                <Trigger SourceName="DetailsButton"
                         Property="IsChecked"
                         Value="true">
                    <Setter Property="Height"
                            Value="100" />
                </Trigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

我已将 Button 更改为 ToggleButton ,因此它可以具有两种状态,并显示清晰的指示.

I have changed Button to a ToggleButton so it can have two states and also shows clear indications.

在触发器中,当我选中按钮时,我已将高度设置为100.一旦条件为假,它将被还原

in the trigger i have set the height to 100 when the button is checked. and it will be reverted back once the condition become false

看看这是否是您想要的.

see if this is what you are looking for.

这篇关于C#Wpf如何使用其中的按钮更改Listviewitem的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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