WPF window size - wpf

I am creating a Notepad like application in WPF. I want to set the window form height and width according to screen size . How can i get Screen height and width ?

Just bind SystemParameters properties to your window properties.
<Window x:Class="YourWindow"
Height="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Height}"
Width="{Binding Source={x:Static SystemParameters.WorkArea}, Path=Width}">

See System.Windows.SystemParameters
You have properties like
PrimaryScreenWidth
PrimaryScreenHeight
VirtualScreenHeight
VirtualScreenWidth
WorkArea
etc.
This question might help as well: How can I get the active screen dimensions?

Related

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 do Silverlight overlay element

I am starting to learn SL...
I am trying to make a MediaElement of size X, and on the bottom of the movie frame some subtitles that will run.
I was unable to understand if I need absolute position or something else.
Please advice
thanks
If you need to us it as a subtitle you just need to put your TextBlock under the MediaElement on your Grid and need to give VerticalAllignment property as bottom on XAML. And it will be over it. Like this;
<Grid>
<MediaElement/>
<TextBlock VerticalAllignment="Bottom"/>
</Grid>
You may refer Grid Layout as relative positioning if you're new to silverlight. And can give a margin to your textblock or anything you want just take a look at the intellisense (if using VS) and you'll understand, if you're using expression blend it'll be a lot easier with UI.
If you want to use absolute positioning you'll need to use Canvas instead of Grid Layout, its the same and you can change anything to canvas with nearly no problem. In canvas, you need to use left and right properties instead of allignments. Like this;
<Canvas>
<MediaElement/>
<TextBlock Canvas.Left="0" Canvas.Top="400"/>
</Canvas>
Another option is stackpanel its not really suitable for LayoutRoot, but its pretty nice for controls. So if you want your subtitles to stay under your movie you should use StackPanel like this;
<StackPanel Orientation="Vertical">
<MediaElement/>
<TextBlock/>
</StackPanel>
So to sum up;
-If you want your subtitles to be on top of your movie use grid like the first example,
-If you have a fixed size and you want to place your subtitles anywhere you want use Canvas,
-And if you want to put your subtitles under your movie use StackPanel.
-My personal choice would be grid. =)
For more information you may check this article it seems like a nice one!
http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-2-using-layout-management.aspx
Happy coding!!
The TextBlock will overlay (within a Grid layout) the MediaElement simply because it is declared after the MediaElement. VerticalAlignment="Bottom" will place it at the bottom of the Grid. You might want to set the Grid's width and height (instead of the MediaElement) that of the size of the video. The MediaElement will auto size to stretch the full size of the grid.
<Grid x:Name="LayoutRoot" Width="480" Height="320">
<MediaElement/>
<TextBlock TextWrapping="Wrap" VerticalAlignment="Bottom"/>
</Grid>

How to get or compute actual width of ListBox without Vertical Scrollbar if visible

I wonder how to get or compute actual width of ListBox without Vertical Scrollbar if visible.
What I want to do is changing width of each items inside ListBox without being covered by Vertical Scrollbar.
Width="{Binding ActualWidth,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}
At least, above binding tell me the actual width of ListBox, but this one does not handle width of vertical scrollbar.
Is there any good way to solve this?
Try binding to the ViewportWidth property of the containing ScrollViewer instead.
Like this:
Width="{Binding Path=ViewportWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ScrollViewer}}"
Maybe the default will help you: just don't set Width at all!
At least in my case it was totally sufficient to not set the Width property. While Mårten Wikström's answer is completely correct I found out my actual problem was I had specified (unnecessarily) Width and did this in a wrong way (the same way Aki24x has reported).
This is a simplified case of my example. The solution was to just delete line 4.
1 <ListBox.ItemTemplate>
2 <DataTemplate>
3 <Border
4 Width="..."
5 >

WPF Height/Width

In a custom WPF control I would like to set the width of the control to be a function of the Height. For example: Width = Height / 3 * x;
What would be the best way to accomplish this so that the control resizes (and initially sizes) correctly and fluidly?
You could bind Width to ActualHeight, and use converter to apply custom function. E.g. the following code makes Button always squared:
<Button Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}}"/>
Hope this helps,
Cheers, Anvaka.

Binding to the actual of a UserControl in Silverlight?

Seen some questions on SO but none answers my question.
What I want to accomplish:
I have a custom control (lets call it A) which moves around the canvas using a storyboard. And I want to bind another custom control's canvas (lets call it B) position onto the first control.
Using the TransformToVisual(Application.Current.RootVisual) I can get the actual position of control A, but I can't figure out how to get a binding to B's Canvas.Left and Canvas.Top on this.
Has anyone figured out how to accomplish this task? Or get me pointed into the right direction?
I presume you move the position of control A by updating its Canvas.Left and Canvas.Right properties? If this is the case, you do not need to use TransformToVisual, you can just bind their Canvas Top & Left properties together:
<Canvas >
<TextBlock x:Name="ControlB"
Text="Some Text"
FontSize="15"
Canvas.Left="{Binding ElementName=ControlA, Path=(Canvas.Left)}"
Canvas.Top="{Binding ElementName=ControlA, Path=(Canvas.Top)}"/>
<TextBlock x:Name="ControlA"
Text="Some Text"
FontSize="13"
Canvas.Left="100"
Canvas.Top="100"/>
</Canvas>
Regards,
Colin E.

Resources