<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeff Wilcox &#187; Visual Basic</title>
	<atom:link href="http://www.jeff.wilcox.name/topics/dev/vb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeff.wilcox.name</link>
	<description>Silverlight, rich client apps and web development</description>
	<lastBuildDate>Mon, 26 Jul 2010 17:56:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>A Silverlight HighlightingTextBlock implemented in Visual Basic</title>
		<link>http://www.jeff.wilcox.name/2009/08/vb-highlighting-textblock/</link>
		<comments>http://www.jeff.wilcox.name/2009/08/vb-highlighting-textblock/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 20:28:48 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/08/vb-highlighting-textblock/</guid>
		<description><![CDATA[Here's a Visual Basic implementation of HighlightingTextBlock for Silverlight 3.]]></description>
			<content:encoded><![CDATA[<p>Using the same steps and control template XAML from my earlier post today about the HighlightingTextBlock control for Silverlight, you can create a Visual Basic implementation of the control alternatively.</p>
<p>Here’s the VB.NET implementation of the control:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:cc9da320-4da9-4d6c-a3cf-eb1828c6c628" class="wlWriterEditableSmartContent">
<pre class="vb" name="code">Imports System.Windows.Controls.Primitives

Public Class HighlightingTextBlock
    Inherits Control

    ' Contants
    ' --------
    Private Const TextBlockName As String = "Text"

    ' Private fields
    ' --------------
    Private Inlines As List(Of Inline)
    Private TextBlock As TextBlock

    ' Dependency properties
    ' ---------------------

    '
    ' HighlightBrush
    '
    Public Shared ReadOnly HighlightBrushProperty As DependencyProperty = DependencyProperty.Register("HighlightBrush", GetType(Brush), GetType(HighlightingTextBlock), New PropertyMetadata(Nothing, New PropertyChangedCallback(AddressOf HighlightingTextBlock.OnHighlightBrushPropertyChanged)))

    Public Property HighlightBrush() As Brush
        Get
            Return TryCast(MyBase.GetValue(HighlightingTextBlock.HighlightBrushProperty), Brush)
        End Get
        Set(ByVal value As Brush)
            MyBase.SetValue(HighlightingTextBlock.HighlightBrushProperty, value)
        End Set
    End Property

    Private Shared Sub OnHighlightBrushPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        TryCast(d, HighlightingTextBlock).ApplyHighlighting()
    End Sub

    '
    ' HighlightFontWeight
    '
    Public Shared ReadOnly HighlightFontWeightProperty As DependencyProperty = DependencyProperty.Register("HighlightFontWeight", GetType(FontWeight), GetType(HighlightingTextBlock), New PropertyMetadata(FontWeights.Normal, New PropertyChangedCallback(AddressOf HighlightingTextBlock.OnHighlightFontWeightPropertyChanged)))

    Public Property HighlightFontWeight() As FontWeight
        Get
            Return DirectCast(MyBase.GetValue(HighlightingTextBlock.HighlightFontWeightProperty), FontWeight)
        End Get
        Set(ByVal value As FontWeight)
            MyBase.SetValue(HighlightingTextBlock.HighlightFontWeightProperty, value)
        End Set
    End Property

    Private Shared Sub OnHighlightFontWeightPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim source As HighlightingTextBlock = TryCast(d, HighlightingTextBlock)
        Dim value As FontWeight = DirectCast(e.NewValue, FontWeight)
    End Sub

    '
    ' HighlightText
    '
    Public Shared ReadOnly HighlightTextProperty As DependencyProperty = DependencyProperty.Register("HighlightText", GetType(String), GetType(HighlightingTextBlock), New PropertyMetadata(New PropertyChangedCallback(AddressOf HighlightingTextBlock.OnHighlightTextPropertyChanged)))

    Public Property HighlightText() As String
        Get
            Return TryCast(MyBase.GetValue(HighlightingTextBlock.HighlightTextProperty), String)
        End Get
        Set(ByVal value As String)
            MyBase.SetValue(HighlightingTextBlock.HighlightTextProperty, value)
        End Set
    End Property

    Private Shared Sub OnHighlightTextPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        TryCast(d, HighlightingTextBlock).ApplyHighlighting()
    End Sub

    '
    ' Text
    '
    Public Shared ReadOnly TextProperty As DependencyProperty = DependencyProperty.Register("Text", GetType(String), GetType(HighlightingTextBlock), New PropertyMetadata(New PropertyChangedCallback(AddressOf HighlightingTextBlock.OnTextPropertyChanged)))

    Public Property [Text]() As String
        Get
            Return TryCast(MyBase.GetValue(HighlightingTextBlock.TextProperty), String)
        End Get
        Set(ByVal value As String)
            MyBase.SetValue(HighlightingTextBlock.TextProperty, value)
        End Set
    End Property

    Private Shared Sub OnTextPropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
        Dim source As HighlightingTextBlock = TryCast(d, HighlightingTextBlock)
        If (Not source.TextBlock Is Nothing) Then
            Do While (source.TextBlock.Inlines.Count &gt; 0)
                source.TextBlock.Inlines.RemoveAt(0)
            Loop
            Dim value As String = TryCast(e.NewValue, String)
            source.Inlines = New List(Of Inline)
            If (Not [value] Is Nothing) Then
                Dim i As Integer
                For i = 0 To [value].Length - 1
                    Dim [run] As New Run
                    [run].Text = value.Chars(i).ToString
                    Dim inline As Inline = run
                    source.TextBlock.Inlines.Add(inline)
                    source.Inlines.Add(inline)
                Next i
                source.ApplyHighlighting()
            End If
        End If
    End Sub

    ' Initializes a new instance of the HighlightingTextBlock control
    Public Sub New()
        Me.DefaultStyleKey = GetType(HighlightingTextBlock)
    End Sub

    ' Enforce the template
    Private Sub OnLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Me.OnApplyTemplate()
    End Sub

    ' Grab the template parts
    Public Overrides Sub OnApplyTemplate()
        MyBase.OnApplyTemplate()
        Me.TextBlock = TryCast(MyBase.GetTemplateChild(TextBlockName), TextBlock)
        Dim text As String = Me.Text
        Me.Text = Nothing
        Me.Text = [text]
    End Sub

    ' Update highlighting using a simple walking algorithm
    Private Sub ApplyHighlighting()
        If (Not Me.Inlines Is Nothing) Then
            Dim text As String = IIf(Me.Text &lt;&gt; Nothing, Me.Text, String.Empty)
            Dim highlight As String = IIf(Me.HighlightText &lt;&gt; Nothing, Me.HighlightText, String.Empty)
            Dim compare As StringComparison = StringComparison.OrdinalIgnoreCase
            Dim cur As Integer = 0
            Do While (cur &lt; [text].Length)
                Dim i As Integer = IIf((highlight.Length = 0), -1, [text].IndexOf(highlight, cur, [compare]))
                i = IIf((i &lt; 0), [text].Length, i)
                Do While ((cur &lt; i) AndAlso (cur &lt; [text].Length))
                    Me.Inlines.Item(cur).Foreground = MyBase.Foreground
                    Me.Inlines.Item(cur).FontWeight = MyBase.FontWeight
                    cur += 1
                Loop
                Dim start As Integer = cur
                Do While ((cur &lt; (start + highlight.Length)) AndAlso (cur &lt; [text].Length))
                    Me.Inlines.Item(cur).Foreground = Me.HighlightBrush
                    Me.Inlines.Item(cur).FontWeight = Me.HighlightFontWeight
                    cur += 1
                Loop
            Loop
        End If
    End Sub

End Class</pre>
</div>
<h3>Related posts</h3>
<ul>
<li><a href="http://www.jeff.wilcox.name/2009/08/sl3-highlighting-text-block/">Creating a highlighting text block for Silverlight 3, revisited</a></li>
<li><a href="http://www.jeff.wilcox.name/2008/11/highlighting-autocompletebox/">Building a highlighting AutoCompleteBox</a></li>
<li><a href="http://www.jeff.wilcox.name/2009/03/sl3-highlighting-autocompletebox/">Silverlight 3 element name binding improvements</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/08/vb-highlighting-textblock/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The Silverlight Toolkit team is on top of your feedback</title>
		<link>http://www.jeff.wilcox.name/2009/02/toolkit-community/</link>
		<comments>http://www.jeff.wilcox.name/2009/02/toolkit-community/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 20:43:34 +0000</pubDate>
		<dc:creator>Jeff Wilcox</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[Silverlight Toolkit]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.jeff.wilcox.name/2009/02/toolkit-community/</guid>
		<description><![CDATA[Earlier this week, Jesse Liberty posted some great tips for providing the Silverlight Toolkit team the right amount of information to help solve your issues. On the team, we’re all out there looking and responding to the feedback – so you’re often going to get a response by the actual developer or designer that created [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this week, <a href="http://silverlight.net/blogs/jesseliberty/archive/2009/02/11/help-the-silverlight-toolkit-ate-my-pc.aspx">Jesse Liberty posted some great tips</a> for providing the Silverlight Toolkit team the right amount of information to help solve your issues. On the team, we’re all out there looking and responding to the feedback – so you’re often going to get a response by the actual developer or designer that created the control, and we want to work to make it right.</p>
<h3>We’re on top of the feedback</h3>
<p>In case you wonder if we see what goes on once you post or create an issue, let me just point out:</p>
<ul>
<li>Many of us are subscribed to RSS or e-mail feeds of the Silverlight.net forum for the controls</li>
<li>Subscribed to the RSS for the Silverlight Toolkit site, including new issues and comments</li>
<li>Our excellent program management team reviews all of this feedback throughout the day, and pings the appropriate experts to look into responding</li>
</ul>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Daily issues e-mail" border="0" alt="Daily issues e-mail" src="http://media.jeff.wilcox.name/blog/view/DailyIssues.jpg" width="685" height="481" /></p>
<p>So we’re very reactive to the community and always looking to open a good dialogue.</p>
<h3>Forums or CodePlex issues?</h3>
<p>One little ask I know that I have is that you try using the <a href="http://silverlight.net/forums/35.aspx">Silverlight.net forum</a> before creating a new issue on CodePlex – this is because often we’re able to resolve machine configuration problems, suggest simple solutions, and so on. If the diagnosis is an issue, we’ll often recommend the opening of an issue.</p>
<p>The forums are the easiest place for us to quickly work through issues, since issues aren’t really setup for having conversations and diagnosing on-the-fly.</p>
<h3>Mirrored issues</h3>
<p>We have a rich infrastructure built up that ties our Microsoft internal Team Foundation Server (TFS) to the CodePlex site. As a result, we mirror a majority of the issues and bugs between the two.</p>
<p>This means that your legitimate issues from the CodePlex will show up in our intense and important ship room, where we prioritize and discuss how to move forward and have the right release.</p>
<p>Talk about power!</p>
<h3>We’re seriously considering your feedback</h3>
<p>If you look at the <a href="http://www.codeplex.com/Silverlight/WorkItem/List.aspx">open issues on CodePlex</a> and sort by votes, you’ll see that we’re addressing the big ones. One particular item rises to the top… and we have heard your feedback very, very clearly.</p>
<p>I hope I don’t get in too much trouble for this one… other than to say, in my enlistment, I see some new files with “VB” in their filenames… </p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Visual Basic samples" border="0" alt="Visual Basic samples" src="http://media.jeff.wilcox.name/blog/view/VbSamples.jpg" width="685" height="433" />&#160;</p>
<p>The other top-voted issue was to change the AutoCompleteBox’s SelectedItem to be settable, and as I <a href="http://www.jeff.wilcox.name/2008/12/selecteditem-dcr/">previously posted</a>, we took care of that one right away. It really helps the data binding situation, and was a really solid example of how the community can drive us to work fast and make the right choices in the controls as we revise them over time.</p>
<p>To close, let me just say: Thanks for all your feedback to date, please keep it up!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jeff.wilcox.name/2009/02/toolkit-community/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
