Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have posed several good questions; however, we often get caught up in finding a solution while overlooking the original problem. Before attempting to answer your questions I would like to explorer you layout expectations.</p> <p>Your provided code suggests that you have a custom control (customVideoControl) whose instance is a height of 300px. The ControlTemplate applied to this control has 4 rows, which have calculated heights based on the instance height. Based on these settings your 4 rows would have the following values:</p> <p>Row 0: 240 Row 1: 20 Row 2: 60 Row 3: 50</p> <p>These total to 370px, which is 70px larger than the control. This means that Row 3 would be completely hidden from view, and Row 2 would be clipped down to the top 40px. I assume that this is not your intention. If this is your intention, then the answers below will hopefully help you on your path. If your intention is to scale the row heights based on a ratio, then you can use star sizing. Your suggested ratio would use the following settings:</p> <pre><code> &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="240*"/&gt; &lt;RowDefinition Height="20*"/&gt; &lt;RowDefinition Height="60*"/&gt; &lt;RowDefinition Height="50*"/&gt; &lt;/Grid.RowDefinitions&gt; </code></pre> <p>If you would still like to measure the height of the rows then there are a few corrections that you need to make.</p> <ol> <li><p>Mathematical operations cannot be performed within markup extensions (the curly braces). Your division approach may not be throwing a xaml parse exception, but I doubt that it is working correctly. A value converter is necessary to accomplish what you want.</p></li> <li><p>TemplateBinding is really just a light-weight version of a RelativeSource binding. Since TemplateBinding is light-weight it doesn't allow for Converters.</p></li> </ol> <p>To get your expected behavior you need to use a Binding with a RelativeSource. Therefore the code you want looks something like this:</p> <pre><code>&lt;RowDefinition Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DivisionConverter}, ConverterParameter=15}" /&gt; </code></pre> <p>Where DivisionConverter is the key of a custom converter. The ConverterParameter in this example allows the developer to pass in a denominator, instead of having to create a separate converter for each number.</p> <p>Here's an example of the custom DivisionConverter you will need to create:</p> <pre><code>public class DivisionConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { // Default to 0. You may want to handle divide by zero // and other issues differently than this. double result = 0; // Not the best code ever, but you get the idea. if (value != null &amp;&amp; parameter != null) { try { double numerator = (double)value; double denominator = double.Parse(parameter.ToString()); if (denominator != 0) { result = numerator / denominator; } else { // TODO: Handle divide by zero senario. } } catch (Exception e) { // TODO: Handle casting exceptions. } } return result; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } #endregion </code></pre> <p>If you wanted to incorporate both division and subtraction in the same Binding you would need to either create a special converter, or use a MultiBinding (which would also require you to create a special MultiBindingConverter).</p>
    singulars
    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.
    3. VO
      singulars
      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