Images

WPF Composites supports adding Images to Composites. In this example, I reference the image in the directory path of the WPF application by using the pack uri syntax.

Also, note further below that you may make an Image "clickable" by making its container subscribe to a MouseSingleClick event.

btn.BeginComposite<Border>()
      .AddImage<Border>(0, 0, @"pack://siteoforigin:,,,/Images/4.png", UriKind.Absolute, 30D)
      .EndComposite<Border, BorderArgs>(null);

There are methods specific to Images within BeginSettings, including:
- SetImageMargin
- SetImageHorizontalAlignment
- SetImageStretch
- SetImageStretchDirection
- SetImageVisibility
- SetImageClip (to clip the shape of the Image to the shape of a geometry path).

See example here of defining Image settings on a Border that will be applied to any Image added to that Border later on in the code . . . such as in a BeginComposite . . . EndComposite call.

//Create an EllipseGeometry to serve as the pattern for clipping or cutting out a shape from the image
EllipseGeometry myEllipseGeometry = new EllipseGeometry();
            myEllipseGeometry.Center = new Point(15, 15);
            myEllipseGeometry.RadiusX = 15;
            myEllipseGeometry.RadiusY = 15;

//Add settings to the Border to be applied on eventually adding the Image
btn.BeginSettings<Border>()
      .SetImageMargin<Border>(0, 0, new Thickness(4))
      .SetImageClip<Border>(0, 0, myEllipseGeometry)
      .SubscribeMouseSingleClickOnBorder<Border>((o, ev) =>
       {
                MessageBox.Show("Test 4");
        })
      .EndSettings<Border>();

Last edited May 25, 2014 at 9:30 PM by stagathome0069, version 6

Comments

No comments yet.