Class Application
' Application events, such as Startup(), Exit(), and DispatcherUnhandledException
' can be handled in this file
Public Shared Function IsInDesignMode() As Boolean
Return ComponentModel.DesignerProperties.GetIsInDesignMode(New DependencyObject())
End Function
End Class
Public Class NodesMissingToHidden
Implements IMultiValueConverter
Public Function Convert(ByVal values() As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IMultiValueConverter.Convert
Dim ret As System.Windows.Visibility = Visibility.Visible
'If we are in design mode then we want to show the element no matter what
If Application.IsInDesignMode = True Then
Return ret
End If
'loop through the values, if any value is missing in the array then set Visibility.Hidden
For Each o In values
If o Is Nothing OrElse o.Equals(DependencyProperty.UnsetValue) Then
ret = Visibility.Collapsed
End If
Next
Return ret
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetTypes() As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object() Implements System.Windows.Data.IMultiValueConverter.ConvertBack
Throw New NotImplementedException()
End Function
End Class
<Page x:Class="Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:z="clr-namespace:WpfBrowserApplication1"
Title="Page1">
<Grid Name="MyGrid">
<Grid.Resources>
<XmlDataProvider x:Key="MyXML" />
<z:NodesMissingToHidden x:Key="NodesMissingToHidden" />
</Grid.Resources>
<StackPanel>
<TextBlock >
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource NodesMissingToHidden}" >
<Binding Source="{StaticResource MyXML}" XPath="Movies/Movie[@Name='Star Wars']" />
</MultiBinding>
</TextBlock.Visibility>
Click here to goto <Hyperlink NavigateUri="http://www.starwars.com" Foreground="Blue">Star Wars</Hyperlink>
</TextBlock>
<!--Note this movie is not in the XML so the link should NOT show in RUNTIME, yet it should in DESIGN time-->
<TextBlock >
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource NodesMissingToHidden}" >
<Binding Source="{StaticResource MyXML}" XPath="Movies/Movie[@Name='The Sound of Music']" />
</MultiBinding>
</TextBlock.Visibility>
Click here to goto <Hyperlink NavigateUri="http://www.soundofmusic.com" Foreground="Blue">The Sound of Music</Hyperlink>
</TextBlock>
<TextBlock >
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource NodesMissingToHidden}" >
<Binding Source="{StaticResource MyXML}" XPath="Movies/Movie[@Name='Spiderman']" />
</MultiBinding>
</TextBlock.Visibility>
Click here to goto <Hyperlink NavigateUri="http://www.spiderman.com" Foreground="Blue">Spiderman</Hyperlink>
</TextBlock>
</StackPanel>
</Grid>
</Page>
Class Page1
Private Sub Page1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim xml As New System.Xml.XmlDocument()
xml.LoadXml("<Movies><Movie Name='Star Wars' /><Movie Name='Superman' /><Movie Name='Spiderman' /></Movies>")
Dim dp As XmlDataProvider
Dim g As Grid = Me.MyGrid
dp = CType(g.Resources("MyXML"), XmlDataProvider)
dp.Document = Xml
End Sub
End Class
| You must Sign In to use this message board. | |||||
|
|||||