Silverlight DataGrid:使用VisualStateManager隐藏列 [英] Silverlight DataGrid: Hiding columns using VisualStateManager
本文介绍了Silverlight DataGrid:使用VisualStateManager隐藏列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以隐藏datagrid的列,而不使用codebehind?
例如通过使用 VisualStateManager
?
Is it possible to hide a column of a datagrid, without using codebehind?
E.g. by using the VisualStateManager
?
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
x:Class="Buttons.MainPage"
Width="640" Height="480">
<StackPanel x:Name="LayoutRoot" Width="624" HorizontalAlignment="Right" Margin="0,0,8,0" >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="EditStates">
<VisualState x:Name="ReadOnly" />
<VisualState x:Name="Edit">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ShownInEditMode" Storyboard.TargetProperty="(UIElement.Visibility)" BeginTime="00:00:00" Duration="00:00:00.0010000">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<data:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding BBRNumbers}">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="AlwaysShown" Width="80" Binding="{Binding Municipality}" />
<data:DataGridTextColumn Header="ShownInEditMode" Width="73" Binding="{Binding Estate}" Visibility="Collapsed" />
</data:DataGrid.Columns>
</data:DataGrid>
</StackPanel>
列,但这不工作。
VisualStateManager.GoToState(this, "Edit", false);
任何想法?
推荐答案
我还没有想到一个简单的解决方案。不过,我唯一公平的说,我至少告诉你为什么这不工作。为了动画化属性,属性需要为 DependencyProperty
。 可见性
属性 DataGridColumn
不是 DependencyProperty
因此它不会动画。
I haven't been able to come up with a simple solution to this as yet. However its only fair that I at least tell you why this isn't working. In order to animate a property the property needs to be DependencyProperty
. The Visibility
property of the DataGridColumn
is not a DependencyProperty
, hence it does not animate.
这篇关于Silverlight DataGrid:使用VisualStateManager隐藏列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文