免费代码隐藏,使用数据触发器更新/调整GridViewColumn的大小

时间:2013-11-13 09:57:13

标签: wpf xaml datatrigger gridviewcolumn

我尝试使用Code-behind-FREE-XAML代码,每次根据新带来的数据按下GridViewColumn / column1时调整Button1的大小(Button1应该带来新数据并调整{{1}与ListView同时,更新数据的代码不会写在这里。)

当执行没有错误时出现,但column1的大小不会改变,即使我尝试发送转储值而不是column1,例如auto,以查看它是否改变了它的大小,这意味着我没有达到正确的价值!

如何在Setter中达到column1的宽度值?这种方法最终会起作用还是另一种必要的方法?

我已经编写了一个功能齐全的Code-Behind但现在由于MVVM的原因,我必须完成模拟Code-behind-FREE,为了比较和参考,你会在XAML代码之后找到它!

提前致谢!

XAML的代码

100

代码隐藏版本(工作正常,但必须使用代码隐藏版本!)

     <ListView.View>
            <GridView x:Name="dataGridView1">     
                <GridView.Columns >
                    <GridViewColumn x:Name="column1" >
                        <ContentControl>
                            <Style>
                                <Style.Triggers> 
                                   <!--the resize will happen here by triggering using the button-->
                                    <DataTrigger Binding="{Binding ElementName=Button1, Path=IsPressed}" Value="True"> 
                                        <Setter Property="GridViewColumn.Width" Value="auto" /> 
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding ElementName=Button1, Path=IsPressed}" Value="False">
                                        <Setter Property="GridViewColumn.Width" Value="auto" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>                        
                        </ContentControl>

0 个答案:

没有答案
相关问题