<Grid Name="maingrid">
<Viewbox Stretch="Fill" Height="Auto">
<dp:DockablePanel x:Name="dockPanel" Width="980" Height="710" Margin="0,60,0,0" VerticalAlignment="Top" HorizontalAlignment="Center">
<dp:DockablePanel.DockPanelCollection>
<dp:ChildPanel StripTitle="" Dock="Left" ParentName="Window1" Eve_MenuItemClicked="menuAssets_GotMouseCapture" ScrollViewer.VerticalScrollBarVisibility="Hidden" >
<dp:ChildPanel.OpacityMask>
<LinearGradientBrush EndPoint="0.131,0.161" StartPoint="0.143,0.163">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</dp:ChildPanel.OpacityMask>
<dp:ChildPanel.Effect>
<DropShadowEffect BlurRadius="6" Color="#FF000000" Direction="-60" Opacity="0.68" ShadowDepth="0"/>
</dp:ChildPanel.Effect>
</dp:ChildPanel>
</dp:DockablePanel.DockPanelCollection>
<dp:DockablePanel.CenterContent>
<TextBlock></TextBlock>
</dp:DockablePanel.CenterContent>
</dp:DockablePanel>
</Viewbox>
where works ok on my system where my screen resolution is 1024 and 768,but the font (menu panel font ) gets stretched on running this exe on another system (with monitor screen resolution (1280 ,768) or (1366,768) ,please provide me a solution regarding this
When you expect your application to properly run in full-screen mode, you need to think about a real layout.
If your application has to run on systems with different aspect ratios like 4:3 (1024x768), 5:3 (1280x768) and 16:9 (1366x768), you can not simply put everything in a ViewBox and expect it to fill the entire screen and at the same time keep the aspect ratio.
Either you incorporate a layout that allows for different aspect ratios, or you simply don't fill the screen. Consider dropping your top-level ViewBox and read about the layout options offered by e.g. Grid.
<Viewbox Stretch="Uniform" Height="Auto">
Related
I am trying to achieve a grid, with a shadow on just one side and no trace of any shadow on any of the other sides. I tried fiddling around with the direction property of the DropShadowEffect.
What I have tried:
<Grid Background="Transparent" Grid.Row="0" Grid.Column="1">
<Grid Background="White"/>
<Border CornerRadius="0,5,0,0" BorderBrush="White" BorderThickness="0" Background="White">
<Border.Effect>
<DropShadowEffect BlurRadius="5" Direction="355" RenderingBias="Quality" ShadowDepth="2"/>
</Border.Effect>
</Border>
</Grid>
</Grid>
This is what happens with my code:
I want to achieve a drop shadow only visible on the bottom side of the grid, and no trace of the shadow on any of the other sides. The above code leaves a thin gray trail on the left side, which wouldn't work for me.
Sorry if this is a silly question, I am kinda new to WPF.
I don't think the DropShadowEffect has any functionality built-in for this sort of application, however, I managed to achieve the required result using a rectangle and filling it with a linear gradient.
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.3">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#00131313" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
To maintain the same width as the parent of the shadow, add them to the same grid and the same column, set the horizontal and vertical alignment to stretch and the shadow will look consistent.
Then I positioned the rectangle in place of the shadow. Seems a little wanky, but works nonetheless.
Edit:
I found another solution which seems way more better, using the ClipToBounds property and the BorderThickness property.
<Border ClipToBounds="True" BorderBrush="White" BorderThickness="0,2,0,0">
<Border.Effect>
<DropShadowEffect ShadowDepth="2" BlurRadius="10"/>
</Border.Effect>
</Border>
Using a border and a drop shadow is easier than using a rectangle and tweaking it till it looks natural.
Usage of grids is advised to position the border perfectly.
I'm styling a simple graphical object in Silverlight, which is shown as a red rectangle with some white text on it; when the mouse hovers the rectangle, I want to show an overlay rectangle which fades from red to transparent, so that the text is only partially visible. My problem is, the LinearGradientBrush I'm using does not go from red to transparent but from red to some kind of semi-transparent white! I've reproduced the problem as follows:
<Grid x:Name="LayoutRoot" Background="Red">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid>
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="Transparent" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</Grid.Background>
</Grid>
In this case, you can easily see that the upper part of the grid is slightly lighter than the lower part, even though I've used the Transparent color constant. The result is identical if I use #00FFFFFF, while if I use #00xxxxxx, where xxxxxx is the RGB code of any color, the hue of the upper rectangle changes according to the color! Shouldn't the first two digits of the code represent the alpha channel? Why doesn't "00" mean full transparency? Any hint is appreciated.
I have a borderless window created for my WPF application. It resizes perfectly on the sides and corners and also when I drag it to the left or right side of the screen it perfectly scales to fit half the screen. If I use a button or other control event to maximize the window it works perfectly. However, when I drag the window to the top of the screen, the actual window maximizes but the grid inside it does not.
I have it set up to call a method on the sizeChanged event that sets the size of the grid relative to the window (it fills the entire window except 10 pixels on each edge). At first, I thought the sizeChanged event wasn't firing so I created a thread to just detect if the windowState was maximized. On detection it would simply run the method to size up the grid. The method ran, but the grid size didn't change. Only this method of maximization is a problem.
How do I fix this problem?
Edit: XAML
<Window.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF868686" Offset="0" />
<GradientStop Color="Black" Offset="1" />
</LinearGradientBrush>
</Window.Background>
<Grid Background="{x:Null}" Name="baseGrid">
<Grid Height="342" HorizontalAlignment="Stretch" Name="grid1" VerticalAlignment="Stretch" Width="718" Background="#46BA0000">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="6,6,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="maximize" />
</Grid>
</Grid>
I'm also using a style and a theme in my application but this problem happens even when they aren't involved so i didnt include them in the XAML
One solution you can try is to put VerticalAlignment="Stretch" and HorizontalAlignment="Stretch" on your grid control
Other solution is to use e.NewSize.Width and e.NewSize.Height to calculate the grid height and width on Window's SizeChanged event handler.
I have a wpf mvvm application.
And have a GRID with multiple columns
whats best way to set the back ground color of grid-column in wpf?
dabble125's answer was perfect but to give you a sample and to mention a note that it is important where to place your rectangle see the code:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!-- this is not a good place for text block.
the text block is beneath the rectangle
so it would not be seen -->
<!--<TextBlock Grid.Column="1" Text="Some Text"/>-->
<Rectangle Grid.Column="1" Grid.RowSpan="1000">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF83FF97" Offset="0" />
<GradientStop Color="White" Offset="1" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Column="1" Text="Some Text"/>
</Grid>
One way:
Create a rectangle and set its fill to the color of your choice.
Then set its Grid.RowSpan value to a large number or the number of rows you have.
Create a rectangle and set its fill to the color of your choice.
Only having :
<Rectangle
Grid.Column="1"
Fill="#e8ebf1" />
works for me.
The Grid.RowSpan of previous answers is actually useless, and the LinearGradientBrush demonstrated is over-complicated for what is asked.
I am developing a product scrolling feature where products info( product image, Name, price)will be shown side by side horizontally. i need to show the image of the product and also its reflection. under the reflected image i need to show the Prod Name and its price.
The problem here is i dont want to show the complete reflected image.
the oputput should be something like this
Image Height-100%
Reflected Image Height-20%
Product name
Product Price
The above pattern will repeat horizontally.
I am able to get the desired output with some problem. The reflected image is shown up with hieght 100% and the sapce between the actual image and product name is very high.
My reflected image should be a rotated image of the actual image and only half part of the actual image should be shown.
Sample Code so far..
<ListBox Name="testing" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate >
<DataTemplate>
<StackPanel Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" >
<Image Source="{Binding ImageUrl}" Width="200"/>
<Image Source="{Binding ImageUrl}" Width="200" RenderTransformOrigin="0.5,0.5" Opacity="0.3">
<Image.RenderTransform>
<ScaleTransform ScaleY="-1" ScaleX="1"></ScaleTransform>
</Image.RenderTransform>
<Image.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0.5"/>
<GradientStop Color="#FFFFFFFF" Offset="1.0"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" />
<TextBlock Text="{Binding Price}" HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Any pointers even is highly appreciated
For your scale transform, instead of -1, you may want to use a value like .2 since you want it to be 20% the height of the object.
As Jeff points out in order to compress the reflected image to 20% of the originals height you need a ScaleTransform with a ScaleY value of -0.2. The problem is that Render Transforms occur after the layout slot for the element as been allocated. Hence just setting you existing ScaleY value just leaves a 20% height image floating in middle of the same 100% space that the un-transformed image needs.
The Silverlight Toolkit LayoutTransformer control is designed to allow transforms to be applied to content before the layout slot for the control has been allocated. It can then inform its container of the actual space needed post transform.
With this control available change your second (reflected) image element to this:-
<toolkit:LayoutTransformer >
<toolkit:LayoutTransformer.LayoutTransform>
<ScaleTransform ScaleY="-0.2" ScaleX="1" />
</toolkit:LayoutTransformer.LayoutTransform>
<Image Source="Test.png" Width="200" Opacity="0.9">
<Image.OpacityMask>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0.1"/>
<GradientStop Color="#FFFFFFFF" Offset="1.0"/>
</LinearGradientBrush>
</Image.OpacityMask>
</Image>
</toolkit:LayoutTransformer>
I've tweaked some of the opacity values to make the effect more visible. Now the LayoutTransformer is performing the 20% scale and then reporting to the containing StackPanel the appropriately reduced height requirements.