I have an Window in which I want to apply drop shadow effect alongside the round corner radius. so far I'm doing something like this:
<Grid Margin="10" x:Name="MainGrid">
<Grid.OpacityMask>
<VisualBrush Visual="{Binding ElementName=MaskBorder}"/>
</Grid.OpacityMask>
<Border x:Name="MaskBorder" Background="#EEF0F8" CornerRadius="10" >
<Border.Effect>
<DropShadowEffect Color="Gray" Opacity=".50" ShadowDepth="10" />
</Border.Effect>
</Border>
<Grid x:Name="ContentGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Background="Red"/>
<TextBlock Grid.Row="1" Background="Blue"/>
</Grid>
</Grid>
but the problem is when I zoom in to to result I see this on right bottom corner. How can i fix this problem. I tried many solutions but nothing worked for me.
Set the Clip property of the inner Grid in a SizeChanged event handler:
private void ContentGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
ContentGrid.Clip = new RectangleGeometry(new Rect(e.NewSize), 10, 10);
}
XAML:
<Grid Margin="10" x:Name="MainGrid">
<Grid.Effect>
<DropShadowEffect Color="Gray" Opacity=".50" ShadowDepth="10" />
</Grid.Effect>
<Grid x:Name="ContentGrid" SizeChanged="ContentGrid_SizeChanged">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Background="Red"/>
<TextBlock Grid.Row="1" Background="Blue"/>
</Grid>
</Grid>
Related
In my WPF app, I have a XAML window that includes auto-sizing titles, sub-titles ad footers, and between them I have other areas that should fill the remaining space.
There is a GridSplitter in the middle that allows users to size the different parts of the screen.
Now, for some strange unknown reason, when I move the splitter, one of the auto-sizing parts on the bottom scales IN THE OPPOSITE DIRECTION OF THE SPLITTER.
The following XAML code is a test layout to reproduce the problem:
<Window x:Class="TestWpfApp.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"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="CornflowerBlue">
<TextBlock>Title</TextBlock>
</Border>
<Border Grid.Row="1" Background="LightSkyBlue">
<TextBlock>Sub-title</TextBlock>
</Border>
<Border Grid.Row="2">
<TextBlock>Auto sizing element</TextBlock>
</Border>
<GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="5" />
<Border Grid.Row="4" Background="CornflowerBlue">
<TextBlock>Header</TextBlock>
</Border>
<Border Grid.Row="5">
<TextBlock>Auto sizing element</TextBlock>
</Border>
<Border Grid.Row="6" Background="LightSkyBlue">
<TextBlock>Footer</TextBlock>
</Border>
</Grid>
Does anyone know why this is happening?
GridSplitter affects its top and bottom element. You now have two borders and GridSplitter between them, so it will "Stretch" between those element. It doesn't know that you want to stretch between two "Auto sizing elements". It will just resize between those two elements where its placed.
I think this is something that you want:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="5" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="CornflowerBlue">
<TextBlock>Title</TextBlock>
</Border>
<Border Grid.Row="1" Background="LightSkyBlue">
<TextBlock>Sub-title</TextBlock>
</Border>
<Border Grid.Row="2">
<TextBlock>Auto sizing element</TextBlock>
</Border>
<GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" Height="5" />
<Border Grid.Row="4">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Background="CornflowerBlue" Grid.Row="0">
<TextBlock>Header</TextBlock>
</Border>
<TextBlock Grid.Row="1">Auto sizing element</TextBlock>
</Grid>
</Border>
<Border Grid.Row="5" Background="LightSkyBlue">
<TextBlock>Footer</TextBlock>
</Border>
</Grid>
So i have WPF application:
<Grid Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="270" />
<RowDefinition Height="200" />
<RowDefinition Height="260" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
</Grid>
In the last Row i have StatusBar:
<Grid Name="gridStatusBar" Grid.Row="3" Margin="0,0,0,0">
<StatusBar>
<StatusBarItem HorizontalAlignment="Left">
<Label
FontSize="13"
FontFamily="Comic Sans MS"
Foreground="Gainsboro"
Margin="0,-3,0,0"/>
</StatusBarItem>
</StatusBar>
</Grid>
So in case of resize my application i cannot see my StatusBar, i try to add VerticalAlignment="Bottom" and VerticalAlignment="Top" but this still
not helped.
Your Grid effectively has a fixed height of 270 + 200 + 260 + 30 = 760.
You should use relative (star *) sizes if you want it to be able to shrink and grow dynamically:
<Grid.RowDefinitions>
<RowDefinition Height="270*" />
<RowDefinition Height="200*" />
<RowDefinition Height="260*" />
<RowDefinition Height="30" /> <!-- only this height is actually fixed -->
</Grid.RowDefinitions>
Another option would be to use another kind of Panel, such as for example a DockPanel and always dock the StatusBar to the bottom:
<DockPanel>
<Grid Name="gridStatusBar" Height="30" DockPanel.Dock="Bottom" Margin="0,0,0,0">
<StatusBar>
<StatusBarItem HorizontalAlignment="Left">
<Label
FontSize="13"
FontFamily="Comic Sans MS"
Foreground="Gainsboro"
Margin="0,-3,0,0"/>
</StatusBarItem>
</StatusBar>
</Grid>
<Grid Name="mainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="270" />
<RowDefinition Height="200" />
<RowDefinition Height="260" />
</Grid.RowDefinitions>
</Grid>
</DockPanel>
I have the following .XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Expander Grid.Row="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<ListView Grid.Row="0"/>
<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5"/>
</Grid>
</Expander>
<Expander Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<ListView Grid.Row="0"/>
<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5"/>
</Grid>
</Expander>
There are 2 expanders with gridsplitters. I want to achieve the following 2 things:
(1) Whenever one expander collapses, the other expander should fill up the space
(2) Whenever one gridsplitter moves, the 2 expanders automatically adjusts their heights to fill up the space.
The behavior is expected to be similar to the Windows Resource Manager Overview window's behavior. Any advice and insight is appreciated
See if this is what you need :
<Window ...>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Expander Grid.Row="0" Collapsed="Expander_Collapsed_1">
<ListView x:Name="Lv1"/>
</Expander>
<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5" Background="#FFB82424"/>
<Expander Grid.Row="2" Collapsed="Expander_Collapsed_1">
<ListView x:Name="Lv2" Grid.Row="0"/>
</Expander>
<GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5" Background="#FFC51A1A"/>
</Grid>
</Window>
Code :
private void Expander_Collapsed_1(object sender, RoutedEventArgs e)
{
DependencyObject dobj = VisualTreeHelper.GetParent(sender as Expander);
while (!(dobj is Grid))
dobj = VisualTreeHelper.GetParent(dobj);
int i = Grid.GetRow(sender as Expander);
Grid grd = dobj as Grid;
grd.RowDefinitions[i].Height = GridLength.Auto;
}
Here's my code (which isn't working btw):
<DockPanel MinWidth="776" Margin="13" LastChildFill="True" Height="522" VerticalAlignment="Top">
<Grid DockPanel.Dock="Top" MinWidth="200">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="*"/>
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
</Grid>
...
</DockPanel>
When I vertically size the control everything just sticks to the top (which I want, except for the middle to stretch).
Thanks in advance!
If you can just stick to dock panels, you do something like the following:
<DockPanel LastChildFill="true">
<DockPanel DockPanel.Dock="Top" Height="70" />
<DockPanel DockPanel.Dock="Bottom" Height="150" />
<DockPanel DockPanel.Dock="Top"><!-- Expandable content here--></DockPanel>
</DockPanel>
You will have to remove some values from the dock panel LastChildFill="True", Height="522" VerticalAlignment="Top" are stopping the grid from sizing.
Try this:
<DockPanel MinWidth="776" >
<Grid DockPanel.Dock="Top" MinWidth="200">
<Grid.RowDefinitions>
<RowDefinition Height="70" />
<RowDefinition Height="*"/>
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Rectangle Fill="Blue" Grid.Row="0" />
<Rectangle Fill="Green" Grid.Row="1" />
<Rectangle Fill="Red" Grid.Row="2" />
</Grid>
</DockPanel>
I want to fill a panel with rectangles, and when the panel is resized, the rectangles should resize as well.
Why doesn't the following work?
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Rectangle Fill="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Rectangle Fill="Green" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Rectangle Fill="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</StackPanel>
</Page>
I would prefer not to use a Grid because of the pain of adding/removing columns and rearranging the children. (I was looking forward to StackPanel because if I wanted to add a yellow Rectangle at the beginning, I just declare it. I don't have to re-order the others by hand.)
Or a UniformGrid:
<UniformGrid Columns="1">
<Rectangle Fill="Red"/>
<Rectangle Fill="Green"/>
<Rectangle Fill="Blue"/>
</UniformGrid>
You're using a StackPanel whose behavior is to take the size of its children. Use a Grid which takes the whole available size:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Fill="Red" Grid.Row="0" />
<Rectangle Fill="Green" Grid.Row="1" />
<Rectangle Fill="Blue" Grid.Row="2" />
</Grid>