I have a ListView that displays a link button. I need the link button only to display if the ‘FileAddress’ string has a value. It should display a simple TextBlock with the Title otherwise.
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Style="{StaticResource LinkButton}" Height="23" Content="{Binding Path=Title}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
Any ideas would be appreciated.
TIA.
I consider the “gridview” a simple component of wpf .. Where is a bit clumsy to carry out this type of change.
You can make three different approaches:
1) Use GridViewColumn.CellTemplateSelector ( http://www.switchonthecode.com/tutorials/wpf-tutorial-how-to-use-a-datatemplateselector )
Although I do not like = (
2) Create a UserControl that behaves as desired.
It seems appropriate and relatively easy
3) Change the button style through a trigger:
or
There are limitations when using the trigger, sometimes you end up having to create a new template for the button, if you know messing with xaml is relatively easy and simple to do.
Sample (I have a button here and I’m changing his image):