silverlighttextblockfillperioddrawingbrush

How to fill the textblock with periods(Silverlight 5)


I have a grid and three columns. Here goes the code:

<Grid x:Name="StaticGrid" 
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Width="450" 
        Margin="3">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="Auto"/>
    </Grid.ColumnDefinitions>
    <TextBlock Text="{TemplateBinding Description}" 
                Grid.Column="0" 
                Height="30" 
                HorizontalAlignment="Left"/>
    <TextBlock Text="......................................................................................................" 
               Grid.Column="1"/>
    <TextBlock Text="{TemplateBinding ParamValue}" 
                Grid.Column="2" 
                Height="30" 
                HorizontalAlignment="Right"/>
</Grid>

So if my grid has a fixed size then this solution is ok, but if it changes dynamically then I don't know how to change the periods dynamically.
I have read this post, but the solution given by Bob Bao is not working in Silverlight(I mean the DrawingBrush object is not supported).
I have also read this post, where Tamir Khason offers to clone the WPF object to use it in Silverlight. I don't want to use such complex solutions.
Does anyone have a better solution?


Solution

  • You can use a path and play with StrokeDashArray property like this :

    <Grid Height="100" Width="100">
        <Path Data="M5,1 L1,1" 
              Height="1" 
              Stretch="UniformToFill" 
              Stroke="Black" 
              StrokeThickness="2" 
              VerticalAlignment="Top" 
              StrokeDashArray="1 1"/>
    </Grid>
    

    Edit : By playing with LinearGradientBrush properties and Height of rectangle (or other ui element)... Change the StartPoint and Height for another dot size...

    <Grid Height="100" Width="100">
        <Rectangle Height="2">
            <Rectangle.Fill>
                <LinearGradientBrush
                      EndPoint="0,0"
                      StartPoint="3,0"
                      MappingMode="Absolute"
                      SpreadMethod="Repeat">
                    <GradientStop Color="Black" Offset="0.5"/>
                    <GradientStop Offset="0.5"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>