WPF windowstate - wpf

form does'nt open in maximum size even though I set in wpf
enter image description hereenter image description here

Good Morning,
I have done its with c# :
this.WindowState = WindowState.Maximized;

Related

Printing In Silverlight. Some pages missing

I am maintaining an old application that prints checks from silverlight.
The checks are in a grid and the user selects them and presses the print button.
I verified that all the checks selected in the grid do get sent to the printer but I noticed that sometimes some are missing in the actual printout. I check the EndPrint even for errors and there is none.
How can I make sure all the data gets actually printed?
Here is the code for the printpage event
StackPanel stackPanel = new StackPanel();
CheckInfo check = selectedChecks[printItemIndex];
PrintCheck printCheck = BuildPrintCheck(check);
stackPanel.Children.Add(printCheck);
stackPanel.Measure(new Size(args.PrintableArea.Width, double.PositiveInfinity));
if (++printItemIndex < selectedChecks.Count)
args.HasMorePages = true;
args.PageVisual = stackPanel;
I found a workaround to this issue posted here
http://www.thomasclaudiushuber.com/blog/2009/11/25/how-to-print-dynamically-created-images-in-silverlight-4-beta/
Basically instead of putting the Image straight into the page, put a Rectangle and and at run time load the image dynamically, set it as the image source for an image brush and then set the fill property of the rectangle to the image brush.
OK it turned out that SilverLight5 (runtime) has an issue with printing images. The problem does not exist on clients running SilverLight4.
Here is how I fixed it in my code
private void PlaceImages()
{
var logoStreamResourceInfo = Application.GetResourceStream(new Uri("myApp;/Images/logo.png", UriKind.Relative));
var logo = new BitmapImage();
logo.SetSource(logoStreamResourceInfo.Stream);
var logoImageBrush = new ImageBrush();
logoImageBrush.ImageSource = logo;
upperLogo.Fill = logoImageBrush;
lowerLogo.Fill = logoImageBrush;
}

How to handle rotation of WPF Application to be used on Tablets

I'm currently working on a WPF application which will run on Windows 8.1 tablet and I don't find any posts about the following issue :
My application needs to be full screen, so, I set for my views :
WindowState="Maximized"
WindowStyle="ToolWindow"
All right - my application will be displayed in full screen mode:
But, if I rotate the tablet a space is allocated and the application is not in full screen.
I don't want this scenario to happen, the application should stay always in full screen.
I tried to listen SystemEvents.DisplaySettingsChanged event and manually set full screen:
SystemEvents.DisplaySettingsChanged += Current_SizeChanged;
private void Current_SizeChanged(object sender, EventArgs eventArgs)
{
this.WindowStyle = WindowStyle.None;
this.ResizeMode = ResizeMode.NoResize;
this.WindowState = WindowState.Maximized;
this.UpdateLayout();
}
As you can see, i tried even to update layout, but still, not working!
What is strange, is the fact that if you start the application in any position but not in the normal one, it will work. For ex: if the application is started in portrait mode, rotation will not change the dimensions of the window, but if you run the application starting from landscape mode... the bug appears.
You can debug this issue using Ctrl + Alt + Arrows.
Any suggestions?
Edit: It seems that the problem is caused by keyboard. The reserved zone is for keyboard, but i don't find a way to resize to full screen. Actual width, Width and Desired Width are all the same...
Edit2: This bug can be reproduced only on Windows 8.1
You can use DisplaySettingsChanged event of the SystemEvents class. Here is an example -> How to Detect Screen Rotation
Use a property in viewmodel which will set in the Current_SizeChanged method. Then put a data trigger on this boolean and apply RotateTransform 90deg to your LayoutTransform.
A workaraund for this bug is to listen to DisplaySettingsChanged and manually set windows state to normal and after windows state to maximized, like below :
SystemEvents.DisplaySettingsChanged += Current_SizeChanged;
private void Current_SizeChanged(object sender, EventArgs eventArgs)
{
this.WindowState = WindowState.Normal;
this.WindowState = WindowState.Maximized;
}
This is caused by :
WindowStyle="ToolWindow"
Hope microsoft will solve this bug (I submitted the bug on WPF threads on MSDN). Thank you for your help!

How to bind a image in Label in WPF using pure code?

I am new to WPF, here I am making a jigsaw game but encountering a problem: I just don't know how to let a image show in a Label in pure code (in XAML, I can do it.), I have searched google a lot but seems that no releated articles regarding this topic. Anyone can help me on this? thx.
My Code Sample:
Label lbl = new Label();
lbl.Width = 120;
lbl.Height = 120;
lbl.Background = new SolidColorBrush(Colors.YellowGreen);
BitmapImage myImageSource = new BitmapImage();
myImageSource.BeginInit();
myImageSource.UriSource = new Uri("Images/test.png",UriKind.Relative);
myImageSource.EndInit();
lbl.Background.SetValue(ImageBrush.ImageSourceProperty, myImageSource);
myGridContainer.Children.Add(lbl);
well, this code sample can't work. why ? any comment or answer from you will be appreciated , thx.
You can use BindingOperations.SetBinding to data-bind a DependencyProperty to its source.
See also: How can I create a tiled image in code that is also data-bound?

How to change the background of a grid to an image in WP7 silverlight?

I'm trying to set a background for a grid control in WP7 silverlight, I need to do that programatically, not in the desighn.
I tried something like:
ContentPanel.Background = new BitmapImage(new Uri("Images\Backgrounds\with box\13.jpg", UriKind.Relative));
But of course, I got an error, because on the right hand we should have the type SolidColorBrush.
is there a way to do that?
Thanks..
I would firstly recommend that you use a Canvas instead of a Grid. You can do this by deleting the Grid and inserting a Canvas through the Toolbox -> Drag and Drop.
Then, you can use the code as simple as:
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri("url", UriKind.Relative));
CanvasName.Background = imageBrush;
That will change the background to whatever you want.
Hope that helps.

Binding Image Control to URI in WP7

I ham developing an application for WP7 and i am having a strange problem with Image control, it does not show the image it is binded to.
I have tryed it in so many ways but event this way (the most naive one) does not work:
In the xaml I have an Image control named img and this is what I have done in the code behind
public MainPage()
{
InitializeComponent();
img.Source = new BitmapImage(new Uri (#"http://img11.imageshack.us/img11/5365/photovnj.jpg", UriKind.Absolute));
}
</code>
It seems to simple not to work...
Please help!
This code works fine for me presuming you have img declared as an Image in your xaml.
If not, I'd suggest you have a connection problem from your app running in the emulator or device to the internet.
This is the code I wrote.
image1.Source = new BitmapImage(new Uri(#"http://img11.imageshack.us/img11/5365/photovnj.jpg", UriKind.Absolute));

Resources