locked
Attribute Or Complex Property? RRS feed

  • Question

  • I'm new to WPF and am a little confused on when to use attributes as opposed to complex properties.  For example;

    <ImageBrush ImageSource = "mypic.bmp">
     <ImageBrush.Viewbox>
       <Rect>
         <Rect.Width>
           10
         </Rect.Width>
         <Rect.Height>
           20
          </Rect.Height>
        </Rect>
      </ImageBrush.Viewbox> 
    </ImageBrush>
    
     
    

    or

      <ImageBrush ImageSource="mypic.bmp" 
    Viewbox = "0.4,0.5,0.2,0.2">
      </ImageBrush>
    

    I know one is much shorter but how do we know we are able to use attributes instead of needing to use complex properties?

    Can anything be set using attributes?

     

    Monday, April 4, 2011 12:26 AM

Answers

  • I know one is much shorter but how do we know we are able to use attributes instead of needing to use complex properties?
    I don't have a hard and fast rule for you on that.  Often Intelisense will prompt you with a value, or you can find it in help.  If the value is string, bool, numeric etc you can pretty much assume that you can use an attribute.

    Can anything be set using attributes?

    No, sometimes you need or want to set the value to something that is too complex to be set as an attribute.  For instance if you are setting a BorderBrush to a solid color you can just use an attribute.  You would also use an attribute if you were binding it to a resource.  But if you want to directly set it to let say a LinearGradientBrush you would need the more complex way of setting it.

    HTH


    John Fenton
    Wordmasters Direct Mail and Data Processing Services
    • Marked as answer by Unhandled Monday, April 4, 2011 1:35 AM
    Monday, April 4, 2011 1:12 AM