Align icon in the DropDownButton (MahApps.Metro) - c#

The icon is not aligned by default in the DropDownButton. How can I horizontally align the icon?
I am using MahApps.Metro v1.6.5 and MahApps.Metro.IconPacks v2.3.0.
I have tried to set Padding, HorizontalAlignment and VerticalAlignment for the button, but it didn't solve the problem.
<controls:DropDownButton ArrowVisibility="Hidden" ItemsSource="{Binding MenuItems}" BorderThickness="0" Focusable="False">
<controls:DropDownButton.Icon>
<iconPacks:PackIconEntypo Kind="Menu" VerticalAlignment="Center" HorizontalAlignment="Center" />
</controls:DropDownButton.Icon>
</controls:DropDownButton>
Screenshot: https://i.ibb.co/4NhXZ8S/Untitled.png
I am trying to align the icon inside DropDownButton, but can't remove the padding (you can see it on the screenshot).

Okay, I found the problem. It was arrow, which is visible by default:
https://i.ibb.co/CQmZn3p/Screenshot-22.png
It occupies the space for itself even if it is hidden (ArrowVisibility="Hidden"). In this case ArrowVisibility="Collapsed" should be used instead, it solves the problem.

Related

WPF stretch image without Stretch="Fill"

I am trying to make responsive WPF app which shows image. One of the program's functionalities is selecting a piece of an image by clicking and draging the mouse. I use Point p = e.GetPosition((IInputElement)sender); to find cursor position, and I found out I cannot use Stretch="Fill" because it causes the MouseUp cursor to select a little lower than it should and MouseMove is also inaccurate (I have to drag the mouse a lot further than I should). On the internet, I found the reason for this behavior that you cannot use Fill and have to use None instead. However, the image is much smaller without Fill.
This is my XAML:
<Grid Grid.Row = "1"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment= "Top"
Margin="0,30,0,0">
<Image x:Name= "image1"
Grid.Row = "1"
Grid.Column="1"
Cursor="Cross"
MinWidth="300"
MinHeight="300"
MaxWidth="512"
MaxHeight= "512"
Stretch = "None"
RenderOptions.BitmapScalingMode="NearestNeighbor"
RenderOptions.EdgeMode="Aliased"
VerticalAlignment="Top"
MouseDown="picOriginal_MouseDown"
MouseMove="picOriginal_MouseMove"
MouseUp="picOriginal_MouseUp" />
</Grid>
I don't know how to embed my image so that in the window view it fills the grid without this Fill property and at the same time is responsive for fullscreen. Should I wrap Image with something else from the WPF toolbox?
I find it easier using the background of the picture box to be the image then use the stretch in that. Alternatively, you could use the image with any of the other options, try using the the properties tab, here are the other stretch options tho: None, Fill, Uniform, UniformToFill
Tell me if this helps, tryna get rep, thanks!

Why the icon is inserted crookedly into the button. ะก# WPF

XAML:
<Grid Height="22" VerticalAlignment="Top" Background="#FF1368BD" >
<Button x:Name="ButtonPowerOff" HorizontalAlignment="Right" Height="22" Width="22" Background="{x:Null}" BorderBrush="{x:Null}" Click="ButtonPowerOff_Click">
<materialDesign:PackIcon Width="15" Height="15" Kind="WindowClose" HorizontalAlignment="Center" Margin="0 0 0 0" ></materialDesign:PackIcon>
</Button>
</Grid>
You can try setting the height and width of the button to "auto" and also set the padding to "0" in the button. Also delete the HorizontalAlignment of the icon.
I don't know what library is PackIcon, and that's is important because I don't know it behaviour. But I can tell...
Why do you set the PackIcon size if you have set the Button size?
The problem here is button maybe has default padding making the "effective content" size of the button smaller than image, and the image is doing what you want but "the space needed is greater than i have".
Let the image stretch in the button (without setting the size of it) or let the button fit the image 15x15 size (without setting the size of the button).
Everything in WPF is ready for sizeless/locationless layout. Except Canvas children, of course; and some bizarre behaviour of Image control.
If you can avoid use Width and Height in your controls (sometimes you can't) you should do it. Instead use margins, alignments and paddings. This way you let the window and controls be totally responsive.

ScrollViewer scrollbars not appearing

I'm working on updating previously working app. Testing shows the ScrollViewer acting oddly when the Zoom makes part of the contained images fall off the screen. The original app was created with VS 2013 as a Universal Windows app. The new app is created with VS 2015 as a Universal Windows app though the target build has been shifted to the anniversary release.
My XAML is defined so:
<ScrollViewer x:Name="SV1" Grid.Row="1" HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
SizeChanged="SV1_SizeChanged" ZoomMode="Enabled" >
<StackPanel x:Name="ImagePanel" Orientation="Horizontal" HorizontalAlignment="Center"
VerticalAlignment="Top" >
<Image x:Name="ImageLeft" Stretch="Uniform" />
<Image x:Name="ImageRight" Stretch="Uniform" />
</StackPanel>
</ScrollViewer>
The user can change the ZoomLevel of the ScrollViewer. The zoom change is implemented using SV1.ChangeView(null, null, zoomFactor).
The images visibly change size on the screen, but as they fall off the right or bottom the scrollbars don't appear. Even changing the visibility properties to "Visible" instead of "Auto" doesn't cause the scrollbars to appear. When the size changes and for a brief instant a thin line will appear where the bars should be and then disappear. Additionally, user input that would normally scroll like moving the mouse wheel does nothing.
Based on other commentary, I've tried replacing the StackPanel with a Grid with no apparent effect.
I'm drawing a blank. Any ideas?
It appears the answer is the next control which shares the same visual space needs to be set to Visibility="Collapsed" in the XAML. The visibility is controlled programmatically, but without the XAML tag the scrollbars of the previous control don't appear and with the tag they do.

Button Disappearing on Resize

In a WPF application I'm developing, I intend to have a number of buttons on the left in a separate grid, however, when I resize the application (making it smaller) the button shrinks and eventually disappears.
I know there's obviously something I'm overlooking, but I can't find out what it is.
Here's the XAML for that grid:
<Grid HorizontalAlignment="Left"
Margin="0,23,0,0"
Name="pnlNav"
VerticalAlignment="Stretch"
Width="200">
<Button Content="Team Open"
Height="31"
Name="btnTeamOpen"
Width="144"
Click="btnTeamOpen_Click"
Margin="26,44,30,533" />
</Grid>
Your button has a ridiculous margin: Margin="26,44,30,533"
This means the button has to be over 500px from the bottom, clippling occurs if the available space is smaller than the top margin + height + bottom margin.
(MSDN article on the layout system & Alignment, Margins & Padding)

How do you vertically align check box of the checkbox properly?

When you add a checkbox to a window and center it vertically, superficially it seems it is OK. However when you increase the padding you notice something odd -- the label part of the checkbox is centered indeed, but the check box remains in the left-top corner. So with enough padding you will get such result
[ ]
this is my checkbox
So, question is -- how to align check box of the checkbox properly?
Edits
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<CheckBox Name="XSwitchCheckBox"
VerticalContentAlignment="Center"
VerticalAlignment="Center"
Padding="4">X-axis switch</CheckBox>
</StackPanel>
<Image DockPanel.Dock="Bottom" Name="pictureBox1"></Image>
</DockPanel>
I am not able to reproduce your issue. Are you setting the All property of the Padding property or are you setting the Left property? You may also want to try adjusting the Margin property.
With a Left Padding on my small form my checkbox looks like:
[] checkbo
x1
You may also try, Padding="2,0,0,0" in which you should see the entire checkbox move. I believe in your code you may be setting your padding to a value greater than the space available.
Hopefully this will help you clear this up.
VerticalContentAlignment="Center" worked for me.
Note: VerticalAlignment="Center" does not work since it refers to the control itself, not the contents of the control.
Thanks to Antoine Meltzheim for this answer.
The checkbox layout is done using the BulletDecorator Class. It looks like the padding you are setting is getting applied to the bullet child, not to a container which contains the bullet and the child.

Categories