Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In code behind you will have to use ActualWidth and ActualHeight if you have not explicitly set the Width/Height.</p> <pre><code>Line1.X1 = Grid1.ActualWidth / 2; Line1.Y1 = Grid1.ActualHeight / 2; </code></pre> <p>if you want to do in XAML you can make BindingConverters to perform logic on a binded value.</p> <p>Xaml:</p> <pre><code>&lt;Window x:Class="WpfApplication6.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication6" Title="MainWindow" Height="350" Width="525"&gt; &lt;Window.Resources&gt; &lt;local:DivideByConverter x:Key="Divider" /&gt; &lt;/Window.Resources&gt; &lt;Grid x:Name="LayoutRoot"&gt; &lt;Line Name="Line1" X2="{Binding ElementName=LayoutRoot, Path=ActualWidth, Converter={StaticResource ResourceKey=Divider}}" Y2="{Binding ElementName=LayoutRoot, Path=ActualHeight, Converter={StaticResource ResourceKey=Divider}}" Stroke="Black"/&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>Binding converter:</p> <pre><code> public class DivideByConverter : IValueConverter { /// &lt;summary&gt; /// Converts a value. /// &lt;/summary&gt; /// &lt;param name="value"&gt;The value produced by the binding source.&lt;/param&gt; /// &lt;param name="targetType"&gt;The type of the binding target property.&lt;/param&gt; /// &lt;param name="parameter"&gt;The xmlentry to the language value&lt;/param&gt; /// &lt;param name="culture"&gt;The culture to use in the converter.&lt;/param&gt; /// &lt;returns&gt; /// A converted value. If the method returns null, the valid null value is used. /// &lt;/returns&gt; public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int divider = 2; if (value is double) { return (double)value / divider; } return value; } /// &lt;summary&gt; /// Converts a value. /// &lt;/summary&gt; /// &lt;param name="value"&gt;The value that is produced by the binding target.&lt;/param&gt; /// &lt;param name="targetType"&gt;The type to convert to.&lt;/param&gt; /// &lt;param name="parameter"&gt;The converter parameter to use.&lt;/param&gt; /// &lt;param name="culture"&gt;The culture to use in the converter.&lt;/param&gt; /// &lt;returns&gt; /// A converted value. If the method returns null, the valid null value is used. /// &lt;/returns&gt; public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new Exception("The method or operation is not implemented."); } } </code></pre> <p>This will take the Binded value (ActualWidth) and divide it by two and the same for ActualHeight. So even if your from is resized the line will stay in the center</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload