WPF Border using plain black rectangle - wpf

How can I get the border in WPF to use a plain black rectangle? It always appears to have thicker bottom and left lines which I guess is a shadow effect even though I have no effects applied. I don't want to use a rectangle as I am using this to apply a border around a grid containing controls.

Try setting SnapsToDevicePixels="true". Like this:
<Border Width="200" Height="200"
BorderBrush="Black" BorderThickness="1"
SnapsToDevicePixels="true"></Border>
For me, this removed the varying thickness of the borders.

Related

How can I flatten a WPF border to make a seamless surface?

I have rectangles that have different colored borders to represent different statuses. I'm trying to create a placeholder shape that is just the background color. To make them all uniform sizes, I'm adding a border that is the same color as the default background for this placeholder. You can see it in the image below. However, there's a small inner line, or edge, on the border that I can't get rid of, which prevents it from looking like a "flat" surface. How can I remove that line? The border currently is:
<Border Margin="2.5" BorderBrush="{Binding exampletext, FallbackValue=#00bc00}"
Background="#788585" BorderThickness="4"
CornerRadius="3">
Do not set BorderThichkness and probably BorderBrush is also not needed:
<Border Margin="2.5"
Background="#788585"
CornerRadius="3">
Update: if you need that 4 pixel wide placeholder, you can try with Padding maybe:
<Border Margin="2.5"
Background="#00bc00" Padding="4"
CornerRadius="3">

WPF borders and the controls within them

This post is about the controls contained within a WPF Border control. It's also about having a border that can appear and disappear without affecting the contained controls.
For the record, I'm using C# and WPF and most of the view stuff is using XAML. I also use MVVM although I'm not sure that's going to be related.
What I had planned for was a border around a control that I could make appear and disappear, for the effect of a highlight or something like that. But when I change certain properties of the Border, for example the Opacity or Visiblity, they impact on the contained controls. I have also tried changing the Background property to Transparent and that has not made a difference.
I do know that some controls have a Border property, but that's not really the case for my situation.
How can I do this?
Thanks
Try this:
<Grid>
<Border BorderThickness="2">
<YourControl />
</Border>
<Border Opacity="0.5" BorderBrush="Red" BorderThickness="2" />
</Grid>
This way you can change the opacity of the second border without affecting your control. The trick is that Grid ensures that both elements inside it have the same dimensions.
Also notice how your control is wrapped in another border with the same thickness but with no brush. This is to keep the second border from obscuring your control.

Adding a border to image control prevents image from displaying WPF

I have a perplexing problem that makes no sense to me - I am trying to place a border round an image control in WPF. The image control displays an image perfectly (I have loaded through code behind and XAML and both work fine). However when I place a border around the image control the image does not appear at all. This happening with three image controls all with identical config. Does anyone know why this is or how I can fix it? Many thanks, Jeff.
XAML (with border commented out) is below:
<!--<Border BorderBrush="Black" BorderThickness="2" Margin="201,172,618,450" Grid.Column="1">-->
<Image Name="imgFault11" Stretch="Fill" Grid.Column="1" Margin="200,172,619,450">
<!--</Border>-->
You are putting both in Grid.Column="1"
Put the image in the border
Start with no margins
<Border BorderBrush="Black" BorderThickness="2" Grid.Column="1">
<Image Name="imgFault11" Stretch="Fill">
</Border>
You may have to send the border to the Background. Once you add this it overlays the image. Right click the border .. go to order and then choose "Send to Back". The border control is in the toolbox. This is all a little messy though as getting the border to match the image box size takes time to get right and then you have one control on top of another..etc.

Format and video Resolution like WMP with MediaElement WPF

Hey I would like to know if its possible to do something like that with the MediaElement in WPF:
http://img11.hostingpics.net/pics/374632Captur2e.png
And Like that:
http://img11.hostingpics.net/pics/403059Capture.png
So I When I resize my window the Default resolution stay the same.
Thanks
Just have a look at the code below. It is a MediaElement in a Border in a Grid. The Border is only there to show that the Grid is filled completely. Running this code and resizing the containing window shows that MediaElement well preserves the aspect ratio of its content (a behaviour that may be altered by setting the Stretch property).
<Grid>
<Border BorderThickness="5" BorderBrush="White" Background="Black">
<MediaElement Source="C:\Users\Public\Videos\Sample Videos\Wildlife.wmv"/>
</Border>
</Grid>

How to Centre Silverlight Elements relative to each other?

I have an Ellipse and a TextBlock that I want to be Centred relative to each other - ie the TextBlock shows in the Centre of the Ellipse no matter the content eg. its says 88 (like a Bingo Ball) and the Ellipse is the Ball itself - and the number shows in the centre of this ball.
How to I accomplish this in Silverlight, where the sizes are not fixed, as if possible I want the Ellipse and TextBlock to be the relative size of their parent - which I cannot seem to do in Silverlight either.
Related to this problem is I cannot find the code behind equivelent for "LimeGreen" the colour, which can be set in XAML but not in Code, where only a few Colours are available the in the Color class?
The style of layout desired is provided by the Grid control. However I suspect you would also want the text to scale with the size of the ellipse, this can be acheived with the Silverlight Toolkit Viewbox control:-
<Grid>
<Ellipse Fill="Blue" />
<controlstk:Viewbox>
<TextBlock Text="88" Margin="2" />
</controlstk:Viewbox>
</Grid>
BTW, LimeGreen is #FF32CD32.

Resources