MahApps slider margin - wpf

I am trying to make simple video Player with MahApps. I have a little problem with layout of flyout. I want to put slider into flyout and make its width equal to flyout width.
<Controls:FlyoutsControl>
<Controls:Flyout Padding="0" Name="mediaStatus" Height="auto" CloseButtonVisibility="Collapsed" IsOpen="False" Position="Bottom">
<Slider Padding="0" Margin="0" Style="{DynamicResource FlatSlider}"></Slider>
</Controls:Flyout>
</Controls:FlyoutsControl>
With this code I'm getting something like this:
screenshot
What can I do to delete this margin on the left of the slider.

You must also set TitleVisibility="Collapsed". The title/header is still visible on the left side (with some margin which produces this black space).

Related

How to horizontally align a CheckBox inside a popup?

Question: The following XAML is not hotizontally aligning the CheckBox to center. Setting HorizontalAlignment="Center" as StackPanel's attribute did not make any difference, either. How can we align it to center?
NOTE: I have uploaded a simple test app sample here if anyone wants to test it. This link will expire in 30 days from today July 21, 2021.
<StackPanel>
<Button x:Name="btnTest" Content="Test" Click="btnTest_Click"/>
<Popup Name="MyPopup" Placement="Mouse">
<StackPanel Background="Bisque">
<Button Click="Hide_Click" Margin="10">Hide Popup</Button>
<CheckBox x:Name="chkWebSpeechDefault" HorizontalAlignment="Center">
<CheckBox.RenderTransform>
<ScaleTransform ScaleX=".5" ScaleY=".5"/>
</CheckBox.RenderTransform>
<TextBlock Text="Set default" FontSize="20"/>
</CheckBox>
</StackPanel>
</Popup>
</StackPanel>
Code Behind [Not specifically relevant to the question]:
private void btnTest_Click(object sender, RoutedEventArgs e)
{
MyPopup.IsOpen = true;
}
Display of the above XAML:
As you can noticed the checkbox is not horizontally aligned to center.
UPDATE
I removed the TextBlock and added Content="Set default" attribute to CheckBox. But it still is aligned to the left. I would like it to be aligned as shown below:
You use a RenderTransform in the Popup for the CheckBox to scale it to half its size.
<CheckBox x:Name="chkWebSpeechDefault" Content="Set default" HorizontalAlignment="Center">
<CheckBox.RenderTransform>
<ScaleTransform ScaleX=".5" ScaleY=".5"/>
</CheckBox.RenderTransform>
</CheckBox>
Render transformations are applied before rendering, but after the layout phase (Measure and Arrange). This means that the originally scaled CheckBox (which spans almost the full width of the popup) will in fact be aligned horizontally, but it is barely visible. After that, the CheckBox will be transformed (only for rendering), but its position and size in the layout is still the same as the original, only the scaled rendered image is put in this imaginary bounding box at the top left. That is why it appears not to be centered. You can experiment with this by assigning a large width, e.g. 500, to the Popup, then you will see the centering.
Now, the solution to the issue is to use a different transformation, a LayoutTransform.
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX=".5" ScaleY=".5"/>
</CheckBox.LayoutTransform>
This transformation is applied before the Measure and Arrange steps, so the layout calculation will consider the real size after scaling and the horizontal alignment is applied to the scaled control.
The black line at the bottom using LayoutTransform seems to be a rendering artifact.
<CheckBox x:Name="chkWebSpeechDefault" Content="Set default" HorizontalAlignment="Center" UseLayoutRounding="True">
Enabling layout rounding by setting UseLayoutRounding to true solves the issue.
There are a few related posts on these kind of issues, SnapsToDevicePixels does not work for me.

How to make custom close button in wpf?

I want to create following form but problem is there when I'm setting the margin with negative value then it will not work and hide my cross image. Is this possible to create as it is? or any other way to create this form.
My need:
(in below image black area is transparent)
But now show my form like below image:-
Please let me know appropriate way.
You can't draw outside of your application, without using Adorners or Popups, as Akku says in the comments.
But what you can do is to, instead of making margins negative, make them positive. So that your content (the gradient background), have a margin of 10 or 20 (or whatever number that produces the right amount of spacing.
<Window (.....) AllowsTransparency="True" WindowStyle="None">
<Grid>
<Button VerticalAlignment="Top" HorizontalAlignment="Right" Height="15" Width="15"/>
<Border Margin="15">
<YOUR_CONTENT>
</Border>
</Grid>
</Window>

Adding a border to image control prevents image from displaying WPF

I have a perplexing problem that makes no sense to me - I am trying to place a border round an image control in WPF. The image control displays an image perfectly (I have loaded through code behind and XAML and both work fine). However when I place a border around the image control the image does not appear at all. This happening with three image controls all with identical config. Does anyone know why this is or how I can fix it? Many thanks, Jeff.
XAML (with border commented out) is below:
<!--<Border BorderBrush="Black" BorderThickness="2" Margin="201,172,618,450" Grid.Column="1">-->
<Image Name="imgFault11" Stretch="Fill" Grid.Column="1" Margin="200,172,619,450">
<!--</Border>-->
You are putting both in Grid.Column="1"
Put the image in the border
Start with no margins
<Border BorderBrush="Black" BorderThickness="2" Grid.Column="1">
<Image Name="imgFault11" Stretch="Fill">
</Border>
You may have to send the border to the Background. Once you add this it overlays the image. Right click the border .. go to order and then choose "Send to Back". The border control is in the toolbox. This is all a little messy though as getting the border to match the image box size takes time to get right and then you have one control on top of another..etc.

WPF Border using plain black rectangle

How can I get the border in WPF to use a plain black rectangle? It always appears to have thicker bottom and left lines which I guess is a shadow effect even though I have no effects applied. I don't want to use a rectangle as I am using this to apply a border around a grid containing controls.
Try setting SnapsToDevicePixels="true". Like this:
<Border Width="200" Height="200"
BorderBrush="Black" BorderThickness="1"
SnapsToDevicePixels="true"></Border>
For me, this removed the varying thickness of the borders.

Format and video Resolution like WMP with MediaElement WPF

Hey I would like to know if its possible to do something like that with the MediaElement in WPF:
http://img11.hostingpics.net/pics/374632Captur2e.png
And Like that:
http://img11.hostingpics.net/pics/403059Capture.png
So I When I resize my window the Default resolution stay the same.
Thanks
Just have a look at the code below. It is a MediaElement in a Border in a Grid. The Border is only there to show that the Grid is filled completely. Running this code and resizing the containing window shows that MediaElement well preserves the aspect ratio of its content (a behaviour that may be altered by setting the Stretch property).
<Grid>
<Border BorderThickness="5" BorderBrush="White" Background="Black">
<MediaElement Source="C:\Users\Public\Videos\Sample Videos\Wildlife.wmv"/>
</Border>
</Grid>

Resources