You asked some good questions; however, we often find ourselves finding a solution, ignoring the original problem. Before trying to answer your questions, I would like to examine your layout expectations.
The code you provided assumes that you have a custom control (customVideoControl) whose instance is 300 pixels high. The ControlTemplate applied to this control has 4 rows that calculated the height based on the height of the instance. Based on these settings, your 4 lines will have the following meanings:
Line 0: 240 Line 1: 20 Line 2: 60 Line 3: 50
These amounts are 370px, which is 70px more than control. This means that Row 3 will be completely hidden from view, and Row 2 will be cropped to the top 40px. I guess this is not your intention. If this is your intention, then the answers below will hopefully help you along the way. If you intend to scale the height of the line based on the ratio, you can use the size of the star. Your suggested ratio will use the following settings:
<Grid.RowDefinitions> <RowDefinition Height="240*"/> <RowDefinition Height="20*"/> <RowDefinition Height="60*"/> <RowDefinition Height="50*"/> </Grid.RowDefinitions>
If you still want to measure the height of the lines, you have to make a few corrections.
Mathematical operations cannot be performed in markup extensions (curly braces). Your separation approach cannot throw an xaml syntax exception, but I doubt it works correctly. A value converter is needed to accomplish what you want.
TemplateBinding is really just a lite version of RelativeSource binding. Since TemplateBinding is lightweight, it does not allow converters.
To get the expected behavior, you need to use a binding with RelativeSource. So the code you want looks something like this:
<RowDefinition Height="{Binding Path=Height, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource DivisionConverter}, ConverterParameter=15}" />
Where DivisionConverter is the key of the custom converter. The converter in this example allows the developer to pass in the denominator instead of creating a separate converter for each number.
Here is an example of a custom DivisionConverter element that you need to create:
public class DivisionConverter : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
If you want to enable both division and subtraction in the same Binding, you will need to either create a special converter or use MultiBinding (which will also require the creation of a special MultiBindingConverter).