I have a very simple dockpanel inside a border. But the dock panel seems to have a 1px margin on the right and bottom. I cant seem to get rid of it by setting the margin or the dockpanel nor by setting the padding of the border.
What exactly is causing it and how can I fix it without hacking it (I.E. negative margin on the dock panel)
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Height="350" Width="525">
<Grid>
<Border BorderBrush="Black" BorderThickness="2" Padding="0">
<DockPanel Background="Blue" Margin="0"/>
</Border>
</Grid>
</Window>
No style defined on Border or DockPanel. Tried this on a brand new project and still seeing the white lines
The usual way you get gaps like that in XAML is becasue the UI is being scaled. If you can't find anything that might be scaling it (RenderTransform in a parent, OS settings such as font size, probably other stuff), you could try playing with UseLayoutRounding and SnapsToDevicePixels.
Related
I am looking to get a fix size windows because of content that I am showing. I am struggling because when the extension is run the size of windows is crop to a fix size. The simple example is just modified the default and try to make it 800x600 window. Once the window is up on screen, you can manual adjust and next time it will be fine but I wish to make sure the default is correct.
I seen other questions about like not having fix size and such and nothing seems to work. I understand if user changes the size smaller than it will be that may - but I would like default size to be bigger
<UserControl x:Class="VSIXProject1.ToolWindow1Control"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800"
Name="MyToolWindow">
<Grid MinWidth="800" MinHeight="600">
<StackPanel Orientation="Vertical" Width="800" Height="600">
<TextBlock Margin="10" HorizontalAlignment="Center">ToolWindow1</TextBlock>
<Button Content="Click me!" Click="button1_Click" Width="120" Height="80" Name="button1"/>
</StackPanel>
</Grid>
Source Image
Problem Image
I try following code in Package class as recommended
[ProvideToolWindow(typeof(ToolWindow1),
Width =800,
Height =600,
Style = Microsoft.VisualStudio.Shell.VsDockStyle.AlwaysFloat)]
You can stipulate the initial size of a toolwindow by setting the Width and Height properties, via the ProvideToolWindowAttribute, used to register your toolwindow. Toolwindows are "sticky", with the position, size, dockstate etc being persisted with your other window layout options. Meaning, once the user resizes/docs/floats the toolwindow, it's state gets saved. But you can readily reset it back to the default, using the Windows | Reset Window Layout menu command.
Sincerely,
Hi you can set the Window size in this way
<UserControl x:Class="VSIXProject1.ToolWindow1Control"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
MinWidth = "800"
MinHeight = "600"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800"
Name="MyToolWindow">
Set the MinWidth and MinHeight will ensure that window will never go under that dimension
Simple code:
<UserControl x:Class="MonitravLite.UserControls.Foo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MonitravLite.UserControls"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel>
<!-- 1st example with setting background -->
<Grid Background="Blue" Opacity="0.5">
<TextBlock Text="Grid background"/>
</Grid>
<!-- 2nd example with grid on top-->
<Grid>
<TextBlock Text="Grid on top"/>
<Grid Background="Blue" Opacity="0.5"/>
</Grid>
</StackPanel>
I have various child controls that display states. When any of these children are in a error state, I want the background of the of the container to change color. e.g..e. if one of the children is in an error state, the background should be red.
However if I set the container background (grid in this example), it washes out the children.
If I do the second approach and lay a grid over the top - this doesn't happen?
I have tried setting the Panel.Zindex, but this doesn't help.
What am I missing to make the first example render like the second?
if you set the opacity of the grid all its children will inherit this property and become transparent as well! So instead of making the grid transparent choose a transparent color as a background.
instead of this line:
<Grid Background="Blue" Opacity="0.5">
try this:
<Grid Background="#7f0000FF">
I need to create a UserControl, which is hosted within a "parent" ContentControl who is set with "Center" Horizontal and Vertical alignment.
This control hosts another "child" UserControl, which I would like to be as big as it can get without stretching over the render-able size.
I noticed that if I set the child's size to be bigger than the render-able size, i get the size I want as a "DesiredSize" property on that control.
However I don't see how can I get that information without oversizing the control.
I've created this sample to illustrate the situation, I want "ChildControl"'s pink background to stretch over the entire window.
Just to clarify, I only have control on "ControlableElementA" and "ControlableElementB"
I cannot bind to the main window, in the actual application I use this as an embedded window with varying levels of hierarchy in between..
The "ChildControl" and "ParentControl" are beyond my reach due to constraints above me.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300">
<Grid>
<ContentControl Name="ParentControl" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid Name="ControlableElementA" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ContentControl Name="ControlableElementB">
<Grid Name="ChildControl" Background="Pink" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Button Width="30" Height="30"></Button>
</Grid>
</ContentControl>
</Grid>
</ContentControl>
</Grid>
</Window>
Thanks ahead, I apologize if the description is a little cryptic
HorizontalAlignment and VerticalAlignment as Stretch means "Stretch to the maximum size within the bounds of the parent container."
However, your parent container is set to Center, which means your UserControl effectively has an Auto width and height.
To fix this, simply remove:
HorizontalAlignment="Center" VerticalAlignment="Center"
From the ContentControl.
i have viewport3d and i want to change its background color.
i am very new to Wpf. i didnt understand what to do from other posts. so i ask here.
i changed brush property for viewport3d but it does nothing
<Window x:Class="W3DTinker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="1200">
<Grid HorizontalAlignment="Left" Height="780" Margin="10,10,0,-21" VerticalAlignment="Top" Width="1180">
<Viewport3D Grid.Row="0" Grid.Column="0" x:Name="Viewport" Margin="350,10,10,10" OpacityMask="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}" />
</Grid>
Viewport3D is a control that creates a 3D scene for you to render things into. It does not display anything by itself. If you want a background color behind it, then set the background color on its parent control, which in your case is the Grid that contains it.
I've created a custom WPF user control. The problem is, that sometimes I need a BorderThickness of 0 and sometimes a BorderThickness of 1.
<UserControl ...>
<clay:TextBox x:Name="ClayTextBox"
BorderThickness="1" >
</clay:TextBox>
</UserControl>
If I'm using the control in a xaml document like this:
<clay:TextBox x:Name="ClayTextBox"
BorderThickness="0" >
</clay:TextBox>
... the Border is always 1. How can I solve that?
In your custom control template style, you should set the parent container control as border and then use template binding to bind the border thickness. Here I've assumed that your CustomControl inherits a control that has BorderThickness as a property.
<ControlTemplate TargetType="{x:Type clay:TextBox}">
<Border BorderThickness="{TemplateBinding BorderThickness}">
//Remaining xaml that makes up your custom control.
</Border>
</ControlTemplate>
Have your border Bind its BorderThickness propety to the UserControls one like this:
<UserControl x:Class="UseRcontrolWithProperty.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" x:Name="this"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Border BorderThickness="{Binding ElementName=this, Path=BorderThickness}"></Border>
</Grid>
</UserControl>
that way changing the BorderBrush on the UserControl will change the border brush of the internal border.