I think your first problem is that you haven't quite stated your objective precisely. How exactly is the rectangle supposed to collide with the triangle? What exactly do you want the method to return? The code you linked is actually only returning a single number (since the X of the returned Vector2 is always 0). Your intention seems to be that this number be the distance that _rectB would need to move straight up in order to escape the triangle.
Per your request, I'm going to write it so that the method returns the Vector2 the rectangle would need to move to escape the triangle, where interactions with the sloped edge are moved directly up (or down) enough to extract the midpoint of the bottom (or top) edge from the triangle without reference to the left or right edges. In effect the sloped edge treats the rectangle as though it is a vertical line segment. Note that this will give very strange behavior near the pointy corners of the triangle; to fix this you would want to make those corners interact with the rectangle as though it were actually the diamond formed by the midpoints of its edges. I'll leave that modification to you.
Also, you haven't described what the properties of your triangle object mean; Left, Right, Top, and Bottom are clear enough I suppose, but Slope and B aren't, and if they mean what I suspect, you have a lot of redundancy in the class which might be confusing you.
In your place I would define your Triangle blocks just like Rectangles, but with a couple of added flags to say which half of the Rectangle is real. Hereafter I'm going to write the section for when the bottom-right half of the rectangle is used. You should not have trouble mirroring the algorithm for other choices.
if (tri.UseBottom) {
// check for collision with the bottom
if (rect.Top > tri.Top && rect.Top < tri.Bottom &&
rect.Left < tri.Right && tri.Left < rect.Right) {
// rect top is inside triangle, shove it down
return new Vector2(0, tri.Bottom - rect.Top);
}
if (tri.UseRight) {
// check for collision with the sloped edge
float rectMid = (rect.Left + rect.Right) / 2;
if (rectMid > tri.Left && rectMid < tri.Right) {
// check bottom against sloped edge
float triHeightAtMid =
triTop + ((tri.Right - rectMid) / (tri.Right - tri.Left)) *
(tri.Bottom - tri.Top);
if (rect.Bottom > triHeightAtMid) {
// midpoint of bottom inside triangle, shove it up
return new Vector2(0, rectBottom - triHeightAtMid);
}
else {
// midpoint of bottom above triangle, no collision
return new Vector2(0, 0);
}
}
// rect midline not inside triangle, check for collision with the right
if (rect.Left > tri.Left && rect.Left < tri.Right &&
rect.Top < tri.Bottom && tri.Top < rect.Bottom) {
// rect left is inside triangle, shove it right
return new Vector2(tri.Right - rect.Left, 0);
}
// checked all 3 edges, no collision
return new Vector2(0, 0);
}
else {
// ...
}
}
else {
// ...
}