本文介绍了带有MVVM的Silverlight隐藏并在datagrid中显示控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 你好朋友, 我的数据网格如下所示 Hello friends,I have a datagrid looks like this below <sdk:DataGrid AutoGenerateColumns="False" Height="Auto" MaxHeight="500" HorizontalAlignment="Left" Margin="5" Name="_EmployeeGrid" ItemsSource="{Binding Path= Employees,Mode=TwoWay}" HorizontalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Visibility="Visible" VerticalAlignment="Top" Width="Auto"> <sdk:DataGridTemplateColumn x:Name="Notes1" Header="Notes"> <sdk:DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel Orientation="Horizontal" > <TextBlock MaxWidth="200" TextAlignment="Left" TextWrapping= "Wrap" Text="{Binding Path=Comments, Mode=OneWay}" Width="200" /> <HyperlinkButton Name="btnEllipsis" Visibility="{Binding EllipsisVisibility,Source={StaticResource ViewModel}}" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="15" Content="..." ToolTipService.ToolTip="Click For More" Command="{Binding NotesCommand,Source={StaticResource ViewModel}}" CommandParameter="{Binding}" > </HyperlinkButton> </StackPanel> </DataTemplate> </sdk:DataGridTemplateColumn.CellTemplate> </sdk:DataGridTemplateColumn> </sdk:DataGrid> 我在视图模型中设置可见性属性如下所示/> string _ellipsisVisibility; 公共字符串EllipsisVisibility { get {return _ellipsisVisibility; } set { if(_ellipsisVisibility!= value) { _ellipsisVisibility = value; RaisePropertyChanged(EllipsisVisibility); } } } 设置 EllipsisVisibility =倒塌; 和 EllipsisVisibility =可见; 问题是它不起作用。我基本上有两个要求就是简单地隐藏和显示它。其次基于某些条件,很少有行会有它,并且很少有人不喜欢使用mvvm的Silverlight中的RowDataBound事件。有人可以帮忙吗?and I am setting the visibility property in view model as belowstring _ellipsisVisibility; public string EllipsisVisibility { get { return _ellipsisVisibility; } set { if (_ellipsisVisibility != value) { _ellipsisVisibility = value; RaisePropertyChanged("EllipsisVisibility"); } } }setting EllipsisVisibility="Collapsed";andEllipsisVisibility="Visible";The problem is its not working. I have basically two requirements one is to simply hide and show it. Secondly based on some condition few rows will have it and few won't like RowDataBound like event in silverlight with mvvm. Can anyone please help?推荐答案 嗨Somnath, 试试以下内容: 1.在Dispatcher.BeginInvoke()中提升属性更改通知,如下所示: Dispatcher.BeginInvoke(()=> RaisePropertyChanged(EllipsisVisibility )); 2.如果上述方法不起作用,请尝试以下绑定表达式: < hyperlinkbutton name =btnEllipsis visibility ={Binding EllipsisVisibility,Source = {StaticResource ViewModel},UpdateSourceTrigger = PropertyChanged}... => 更新: 我刚刚注意到,您已将Visibility属性创建为String。这永远不应该是理想的情况。请将属性类型更改为Visibility而不是String。我希望,这一改变对你有用。如果没有,请按照上述步骤操作。 让我知道,接下来会发生什么。Hi Somnath,Try the below things:1. Raise the property change notification inside the Dispatcher.BeginInvoke() like this:Dispatcher.BeginInvoke(() => RaisePropertyChanged("EllipsisVisibility"));2. If the above does not work, try the below binding expression:<hyperlinkbutton name="btnEllipsis" visibility="{Binding EllipsisVisibility,Source={StaticResource ViewModel}, UpdateSourceTrigger=PropertyChanged}" ...="">UPDATE:I just noticed that, you have created the Visibility property as String. This should never be the ideal case. Please change the property type to Visibility instead of String. I hope, this change will work for you. If sont, then follow the above steps.Let me know, what happens next. 这篇关于带有MVVM的Silverlight隐藏并在datagrid中显示控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 14:08