c# - How to only allow WPF Window's height resizable? -


to specific, have window content set usercontrol. , allow users drag increase height of window, width should fixed , non-resizable. guess have such properties modify can't make them behave desired:

  • window.sizetocontent, available values: manual, width, height,

  • widthandheight window.resizemode, available values: canminimize,
    canresize, canresizewithgrip , noresize

  • and of course min/max of height, width of usercontrol

but kind of combination can achieve want?

one way set both minwidth , maxwidth of window same value:

<window x:class="wpfapplication20.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="mainwindow" height="350" minwidth="525" maxwidth="525">     <grid>      </grid> </window> 

edit: if want in code-behind, wrote in comment, follows:

<window x:class="wpfapplication20.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         title="mainwindow" height="350">     <rectangle x:name="childelement"  width="525" fill="red">      </rectangle> </window> 

and in window's constructor, write:

public mainwindow() {     initializecomponent();      binding binding = new binding("actualwidth") { source = childelement };     bindingoperations.setbinding(this, minwidthproperty, binding);     bindingoperations.setbinding(this, maxwidthproperty, binding);  } 

please note: childelement above usercontrol.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -