Silverlight Transparency - silverlight

Question:
Can a constituent UserControl be transparent in parts for it's external container?
Details:
I have a dialog that I'd like to pull into a separate UserControl. The control contains a Border with a background that has an alpha transparency with a Grid inside it that has a white background and all the content. In xaml markup, it looks something like:
<Border Margin="22,28,20,18" BorderBrush="Black" BorderThickness="1" Background="#30D7D7D7">
<Grid Margin="155,148,145,198" Background="#FFFEFEFE">
<TextBlock Margin="17,19,32,20" Text="Dialog part goes here." TextWrapping="Wrap"/>
</Grid>
</Border>
Problem:
When I move that to a user control, even if I set the user control's background to Transparent, it doesn't display a transparent background for the Border; it's solid.

The UserControl itself will have a background color. Make sure the UserControl you've moved your code to has Background=Transparent.

Related

How do I properly draw and scale a Canvas as a WPF background to a control?

I have a StackPanel that needs to contain drawn background. Specifically, my StackPanel needs to have the ability to grow and the rectangle must grow with the StackPanel, but must remain pseudo-anchored to each side at a fixed position.
I've attempted to use the Canvas.Left, Canvas.Right, Canvas.Top and Canvas.Bottom attached properties, but so far they've not worked. Furthermore, this does seem to work when drawing within Canvas objects, just not when they are embedded within a VisualBrush set as a background. How can I accomplish drawing this resizable, rectangular background within my StackPanel?
Below is the state of my current code. I've tried various approaches but none seem to work.
My Code:
<StackPanel DockPanel.Dock="Right" Orientation="Vertical" VerticalAlignment="Center">
<StackPanel.Background>
<VisualBrush Stretch="None">
<VisualBrush.Visual>
<Canvas Background="Magenta" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
Rectangle Fill="#FFDDECF7" Canvas.Left="20" Canvas.Top="20" Canvas.Bottom="20" Canvas.Right="0"/>
</Canvas>
</VisualBrush.Visual>
</VisualBrush>
</StackPanel.Background>
...
</StackPanel>
This currently doesn't render anything. I set the canvas background to magenta just so I could see if it were drawing, and I'm not even seeing that. Other attempts have drawn the canvase, however, the blue rectangle is always stretched to fill the window, regardless of attached canvas property settings.
Sample:
The image below is a sample of what I want. Again, I'm using an ugly Magenta color to show the offset of the internal, blue rectangle. As the StackPanel grows or shrinks, the rectangle needs to be affixed to the top, left, right and bottom.
My suggestion is to place the stackpanel inside a grid:
<Grid DockPanel.Dock="Right" VerticalAlignment="Center" Background="Magenta">
<Rectangle Margin="20" Fill="#FFDDECF7"/>
<StackPanel Orientation="Vertical">
no background...
</StackPanel>
</Grid>
Wrap Canvas into a ViewBox, then work on a ViewBox. As far as I know Canvas doesn't support scalling too well.

WPF Rounded Corners on a Border in a Window Without AllowsTransparency

I have a problem similar to this, but I have a window that cannot have "AllowsTransparency=True" because the WebBrowser inside it would be rendered invisible. The corners of the window come out black and I need them to be transparent.
Changing the background color to transparent has no effect. I've found that you can wrap a border with rounded edges around a popup with this problem, but you can't do that with a window.
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Background="Transparent" AllowsTransparency="False">
<Border Padding="0" Margin="0" BorderThickness="1" CornerRadius="100" Background="AliceBlue">
<StackPanel>
<TextBlock HorizontalAlignment="Center">v This is a webbrowser v</TextBlock>
<Border BorderBrush="red" BorderThickness="5">
<WebBrowser />
</Border>
</StackPanel>
</Border>
</Window>
Any ideas?
---EDIT---
I've tried every form of the WebBrowser Overlay solution, but my specific problem can't use it. I need a solution that has AllowsTransparency="False".
You seems to have a problem of interop between webbrowser window and a wpf window
so when you set wpf window to be transparent it effectively make the browser transparent as browser is in the hierarchy of the main window
so the whole idea to overcome this issue is to host a browser in a separate native window and overlay it on the transparent wpf window
you may follow WebBrowser control on transparent WPF window

System theme color border for WPF UserControl

I have a custom UserControl and I want it to have the same border style that a normal Window.
I try to bind the borderĀ“s color to the system active border color:
<UserControl>
<Border BorderBrush="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}" BorderThickness="4" >
<Grid>
But that just makes the border gray, no mater what the system border color is.
I want that because I have this userControl inside a maximized, semi-transparent Window, that looks like Dimming the rest of the screen.
Is there other Resource to bind to or another way to achieve that?
Or even is there an easier way to make a 'lights out' effect?
Thanks.

Display Control from MainWindow ontop of View

Is it possible to take a control that is created in the Mainwindow and when switching views... make its zindex topmost to display over top of the view?
I tried playing with ZIndex but had no luck.
ZIndex is a Canvas property, so it won't work for other panel types like Grid, etc. If you need it to appear on top, you could have the control inherit from or placed inside a Popup.
Alternatively, if you add it at the very bottom of the main window's XAML, then it should render on top.
you have to tried DockPanel.
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Top"
Background="OliveDrab"
Foreground="Cornsilk"
FontFamily="Veranda"
FontSize="20"
TextAlignment="Center">
</DockPanel>

WPF/Silverlight XAML Stretch Text Size to Fit container?

I've just started to play with WPF.
Is it possible to have the size of the text of a Label or TextBlock size itself to fill it's parent container?
Thanks,
Mark
You can use a ViewBox to visually zoom something to fit within its container. The other solutions here work, but they only stretch the control, not its content. The ViewBox will stretch both.
<!-- Big grid, will stretch its children to fill itself -->
<Grid Width="1000" Height="1000">
<!-- The button is stretched, but its text remains teeny tiny -->
<Button>
<!-- The viewbox will stretch its content
to fit the final size of the button -->
<Viewbox
Margin="4"
VerticalAlignment="Stretch"
Height="Auto">
<!-- The textblock and its contents are
stretched to fill its parent -->
<TextBlock
Text="Bartenders" />
</Viewbox>
</Button>
</Grid>
Depends on the parent container
Grid, DockPanel will stretch your control
StackPanel, WrapPanel will leave it to the control to size itself..
Set HorizonalAlignment/VerticalAlignment to "stretch".
Use DockPanel as parent container
<DockPanel>
<TextBlock />
</DockPanel>

Resources