在我的tool.xaml中使用以下代码,我得到以下datagrid
<slData:DataGrid x:Name="Customer" ItemsSource="{Binding ReturnedItemAttributes}" AutoGenerateColumns="False" HeadersVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" MaxHeight="350" MaxWidth="350">
<slData:DataGrid.Resources>
<ResourceDictionary>
<local:HTTPVisibilityConverter x:Key="httpVisibility"/>
<local:VisibilityData x:Key="visibilityValue"/>
</ResourceDictionary>
</slData:DataGrid.Resources>
<slData:DataGrid.Columns>
<local:ExtendedDataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<local:ExtendedDataGridTextColumn Binding="{Binding Path=Value}" MyVisibility="{Binding Visible, Source={StaticResource visibilityValue}, Converter={StaticResource httpVisibility}, ConverterParameter=Reverse}"/>
<local:CustomDataGridTemplateColumn Width="40" VisibilityBinding="{Binding Visible, Source={StaticResource visibilityValue}, Converter={StaticResource httpVisibility}}">
<local:CustomDataGridTemplateColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton Content="Pdf Link" Height="23" Name="PdfUrl" Width="76" NavigateUri="{Binding Path=Value, Mode=TwoWay}" TargetName="_blank" Margin="5,10,10,7" Foreground="Blue" />
</DataTemplate>
</local:CustomDataGridTemplateColumn.CellTemplate>
</local:CustomDataGridTemplateColumn>
</slData:DataGrid.Columns>
</slData:DataGrid>
上面的代码创建了一个datagrid,如下所示。请忽略column1 column2和column3标头。人们只是回答我的问题:
Column1 column2 Column3
name John pdf
CustomerID 1234 pdf
Customer_url http://www.test.com pdf
我现在只想为customer_url显示cloumn3中的pdf超链接 为所有其他行划行和隐藏。我怎么能实现它。这是MVVM设计模式。以下是我希望数据网格显示的方式:
Column1 column2 Column3
name John
CustomerID 1234
Customer_url http://www.test.com pdf
我的值转换器代码如下:
public class HTTPVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool boolVisbility = (value != null) && value.ToString().StartsWith("http");
boolVisbility = (parameter != null) ? !boolVisbility : boolVisbility;
return boolVisbility ? Visibility.Visible : Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}