Anchit Pancholi
Anchit Pancholi

Reputation: 1214

WPF Window Margin At Runtime not working

I am having WPF windows height and width are fix. When i started the windows on the basic of user input i need to make only half portion visible of window at runtime. I am trying to set margin as below (in Window_Loaded method) but it is not working.

this.Margin = new Thickness(0, -300, 0, 0);

below are the window attribute properties :-

Height="767" Width="1032" Loaded="Window_Loaded" Closing="Window_Closing" Closed="Window_Closed" WindowState="Normal" WindowStartupLocation="CenterScreen" Background="#FFC7C7C7" ResizeMode="NoResize" WindowStyle="None"

Can you please help how can i change windows alignment so it will show only half part to bottom of desktop.

I have attached a image, its a single window in which part 1 need to be cut and part 2 will be visible. enter image description here I tried to change the height of the window but it cut the height from bottom. which cut part 2 instead of part 1.

Thanks

Upvotes: 0

Views: 731

Answers (2)

Hakan Fıstık
Hakan Fıstık

Reputation: 19511

<Window .....>
   <Grid>
      <Grid.RowDefinitions>
          <RowDefinition/>        
          <RowDefinition/>
      <Grid.RowDefinitions/>
      <Grid Grid.Row="0" Name="gridpart1"> ... part 1 </Grid>
      <Grid Grid.Row="1"> ....part 2 </Grid>
   </Grid>
</Window>

and from the code try to set the "Visibility" property of the grid which contains the part one to Collapsed.

this.gridpart1.Visibility = Visibility.Collapsed;

UPDATE : if case you want the top part of the window blank (mean the window size will not shrink int the size) you can follow the same model and use the following statement instead

this.gridpart1.Visibility = Visibility.Hidden;

Upvotes: 0

Salah Akbari
Salah Akbari

Reputation: 39976

Set the Margin on the main Grid within your window instead of the window's Margin:

<Grid x:Name="mainGrid" >

mainGrid.Margin = new Thickness(0, -300, 0, 0);

Upvotes: 1

Related Questions