Unity 2D – How to anchor a sprite to the left side of the camera viewport

using UnityEngine;
using System.Collections;

public class ActualHeroController : MonoBehaviour {

// Use this for initialization
void Start () {


// Update is called once per frame
void Update () {
float camHalfHeight = Camera.main.orthographicSize;
float camHalfWidth = Camera.main.aspect * camHalfHeight;

Bounds bounds = GetComponent().bounds;

// Set a new vector to the top left of the scene
Vector3 topLeftPosition = new Vector3(-camHalfWidth, 0, 0) + Camera.main.transform.position;

// Offset it by the size of the object
topLeftPosition += new Vector3(bounds.size.x / 2,-bounds.size.y / 2, 0);
topLeftPosition.z = 0;
transform.position = topLeftPosition;

WPF Validation Errors not showing on initial load of control or window

I was setting validation errors on the initial load of my view model, and to my annoyance the window would show up like everything was great. The validation code was definitely running, the HasErrors was true, the dictionaries were filled with the errors but the form was like, “What errors?” ┬áThis irritated me. Well, WPF is stupid in this regard and doesn’t handle things properly. If you are like me, you set your datacontext after creating the view. Well, that is the logical way, but if you want validation you need to slightly alter that. I found a work around that fixes the problem, but is a little more annoying. Simply put, pass in your VM to the constructor of the view. Cache that, then set your DataContext(DC) on the load event. Sample code below:

public partial class AcceptRejectViewOldMeetsNew : UserControl
   private object dcToSet = null;
   public AcceptRejectViewOldMeetsNew(object dc)
    dcToSet = dc;
    this.Loaded += AcceptRejectViewOldMeetsNew_Loaded;
  void AcceptRejectViewOldMeetsNew_Loaded(object sender, System.Windows.RoutedEventArgs e)
    DataContext = dcToSet;

Happy Coding!