I want to be able to display hyperlink if the Url is not null, otherwise I do not wish to display the link.
How shall i go about this? Here is my code so far. Example of my list box template:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Background="#CD85C9E9"
Name="spListItem"
Orientation="Horizontal"
HorizontalAlignment="Stretch">
<Label>
<TextBlock Text="{Binding Name}" />
<!-- How to define if Url Is Null -->
<Hyperlink Name="MyLink" Click="MyLink_Click" />
</Label>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
My Class:
public class MyList
{
public string Name{get;set;}
public string? Url{get;set;}
}
I would suggest you following MVVM pattern so all business logic details are encapsulated by ViewModel (or at least keep it in code behind rather than complex View triggers, etc).
So basically you can expose property
Which encapsulates all logic which is aware of right URL format details and in View just bind Visibility to this flag usng BooleanToVisibilityConverter.
In this way you do not need to change a View each time as logic changes