I am attempting to match the videobrush orientation to the orientation of the phone, but I am having issues implementing this solution. My xaml page is set to PortraitOrLandscape, and I would like for the videobrush to be right side up regardless of the phone's orientation. Before adding the orientation changing if statements to the onOrentationChanged event, the following situation is occuring
Phone: Landscape left, Videobrush: right side up
Phone: Portrait, Videobrush, rotated -90 clockwise
Phone: Landscape right, Videobrush, rotated -180 clockwise
XAML
<Rectangle x:Name="videoRectangle" Margin="0,0,0,0">
<Rectangle.Fill>
<VideoBrush x:Name="viewfinderBrush" AlignmentX="Left" AlignmentY="Top" Stretch="UniformToFill">
<VideoBrush.RelativeTransform>
<CompositeTransform x:Name="viewfinderTransform"
CenterX="0.5" CenterY="0.5"/>
</VideoBrush.RelativeTransform>
</VideoBrush>
</Rectangle.Fill>
</Rectangle>
XAML.CS
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
base.OnOrientationChanged(e);
if (e.Orientation == PageOrientation.LandscapeLeft)
{ //do nothing
//The videobrush orientation is currently right side up
}
if (e.Orientation == PageOrientation.Portrait)
{
//the videobrush is currently rotated 90 degrees counter clockwise
this.viewfinderTransform.Rotation = this.camera.Orientation + 90.0;
}
if (e.Orientation == PageOrientation.LandscapeRight)
{
//the videobrush is currently rotated 180 degrees counter clockwise
this.viewfinderTransform.Rotation = this.camera.Orientation + 180;
}
}
And after adding the if statements, the videobrush orientation gets even crazier. What am I doing wrong? I simply would like to have the videobrush oriented right side up regardless of the phone's orientation.
I'm using a simple switch/case to properly rotate the videobrush:
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
base.OnOrientationChanged(e);
switch (e.Orientation)
{
case PageOrientation.Landscape:
case PageOrientation.LandscapeLeft:
videoBrushTransform.Rotation = 0;
break;
case PageOrientation.LandscapeRight:
videoBrushTransform.Rotation = 180;
break;
case PageOrientation.Portrait:
case PageOrientation.PortraitUp:
videoBrushTransform.Rotation = 90;
break;
case PageOrientation.PortraitDown:
videoBrushTransform.Rotation = 270;
break;
}
}
Works nicely for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With