locked
Best Practice UI Resources RRS feed

  • Question

  • Hello MSDN Community,

    Currently I have several UserControls which their only purpose it to display a visual, no functions. For example,

    <Grid> 
         <Rectangle StrokeThickness="0.5" Stroke="{DynamicResource strokeBrush}" > 
              <Rectangle.Fill> 
                   <LinearGradientBrush EndPoint="0.5,1.4" StartPoint="0.5,0">  
                        <GradientStop Color="#FFF4F4F4" Offset="0"/>  
                        <GradientStop Color="#FFADADAD" Offset="1"/>  
                   </LinearGradientBrush> 
              </Rectangle.Fill> 
         </Rectangle> 
         <Path Fill="{x:Null}" 
               HorizontalAlignment="Left" 
               VerticalAlignment="Stretch" 
               Height="Auto" 
               Margin="1,0,0,0" 
               Width="0.5" 
               Stroke="{DynamicResource menuBarAccentStroke}" 
               StrokeThickness="0.5" /> 
         <Path HorizontalAlignment="Stretch" 
               Margin="0,1,0,0" 
               VerticalAlignment="Top" 
               Width="Auto" 
               Height="0.5" 
               Fill="{x:Null}" 
               Stretch="Fill" 
               Stroke="{DynamicResource menuBarAccentStroke}" 
               StrokeThickness="0.5"/>  
    </Grid> 

    The above sample is wrapped in a UserControl tag. I reference this user control many times within my application. It just seems like a waste of resources... I really don't need it to inherit all the elements of a UserControl, do I? What is the best way to implement this?

    Thanks in advance,

    Christopher

    “Somewhere someone is practicing, if you're not and you should meet, you will lose…”
    Thursday, June 12, 2008 2:25 PM

Answers

All replies

  • Please look at my answer in this thread: http://forums.msdn.microsoft.com/en-US/wpf/thread/2dd8bfbc-7046-403b-8196-3cc040db53c8. There it's just one Path, but in your situation you may be able to use the whole grid as a resource.

    If you give it a key like for example "MyRect" and x:Shared="False" you should be able to use it anywhere like this:
    <StaticResource ResourceKey="MyRect" /> 

    hth,
    Marcel
    • Marked as answer by 01000011 Friday, June 13, 2008 12:20 PM
    Friday, June 13, 2008 7:30 AM
  • Thank you. That was exactly what I need.
    “Somewhere someone is practicing, if you're not and you should meet, you will lose…”
    Friday, June 13, 2008 12:20 PM