Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:39:23+00:00 2026-05-14T14:39:23+00:00

I am currently defining few grids as following: <Grid.RowDefinitions> <RowDefinition Height={TemplateBinding Height-Height/5}/> <RowDefinition Height={TemplateBinding

  • 0

I am currently defining few grids as following:

<Grid.RowDefinitions>
   <RowDefinition Height="{TemplateBinding Height-Height/5}"/>
   <RowDefinition Height="{TemplateBinding Height/15}"/>
   <RowDefinition Height="{TemplateBinding Height/20}"/>
  <RowDefinition Height="{TemplateBinding Height/6}"/>
 </Grid.RowDefinitions>

While the division works fine , the subtraction isn’t yielding the output.

Ialso tried like following:

<RowDefinition Height="{TemplateBinding Height-(Height/5)}"/>

Still no result. Any suggestions plz.

Thanks,
Subhen

**

Update

**
Now In My XAML I tried implementing the IvalueConverter like :

<RowDefinition Height="{TemplateBinding Height, Converter={StaticResource heightConverter}}"/>

Added the reference as

<local:medieElementHeight x:Key="heightConverter"/>

In side generic.cs I have coded as following:

public class medieElementHeight : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //customVideoControl objVdeoCntrl=new customVideoControl();
            double custoMediaElementHeight = (double)value;//objVdeoCntrl.customMediaPlayer.Height;

            double mediaElementHeight = custoMediaElementHeight - (custoMediaElementHeight / 5);
            return mediaElementHeight;
        }


        #region IValueConverter Members


         object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

But getting the exception Unknown Element Height in the element RowDefination.

Updating Code @Tony

<Style TargetType="local:customVideoControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:customVideoControl">
              <Grid>
                        <Grid.RowDefinitions>
                         <RowDefinition Height="{TemplateBinding Height-Height/5}"/>
                        <RowDefinition Height="{TemplateBinding Height/15}"/>
                       <RowDefinition Height="{TemplateBinding Height/20}"/>
                       <RowDefinition Height="{TemplateBinding Height/6}"/>
     </Grid.RowDefinitions>
                      <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                          <ColumnDefinition Width="2*"/>
                          <ColumnDefinition Width="2*"/>
                      </Grid.ColumnDefinitions>
                    <MediaElement x:Name="customMediaPlayer" 
                                   Source="{TemplateBinding CustomMediaSource}"
                                   HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Height="{TemplateBinding Height}"
                                   Width="{TemplateBinding Width}"
                                  Grid.Row="0" Grid.ColumnSpan="3"
                                  />
                   </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Now , My implementing XAML file contains is as follows:

<customMediaElement:customVideoControl x:Name="custMediaElement" Width="400" Height="300"  nextBtnEvent="custMediaElement_nextBtnEvent" prevBtnEvent="custMediaElement_prevBtnEvent" Visibility="Collapsed"/>

Now, I want to substract or divide the values depending on the height of custMediaElement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:39:23+00:00Added an answer on May 14, 2026 at 2:39 pm

    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.

    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:

    Row 0: 240
    Row 1: 20
    Row 2: 60
    Row 3: 50

    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:

        <Grid.RowDefinitions>
            <RowDefinition Height="240*"/>
            <RowDefinition Height="20*"/>
            <RowDefinition Height="60*"/>
            <RowDefinition Height="50*"/>
        </Grid.RowDefinitions>
    

    If you would still like to measure the height of the rows then there are a few corrections that you need to make.

    1. 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.

    2. TemplateBinding is really just a light-weight version of a RelativeSource binding. Since TemplateBinding is light-weight it doesn’t allow for Converters.

    To get your expected behavior you need to use a Binding with a RelativeSource. Therefore 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 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.

    Here’s an example of the custom DivisionConverter you will need to create:

    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 && 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
    

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm defining a variety of Fragments in the resource file and hiding them
Currently, I have a Maven project which inherits from a parent pom defining two
I am currently defining the src attribute of my Iframe with the URL +
Currently have this code defining getter/setter for an object's selectedID property. The object is
Currently, we are defining ourselves an extended log mechanism to print out the class
I currently have the following javascript code (loosely modeled after how a similar objective
I am developing a high-traffic java web application. Currently I'm defining its architecture. I
I'm currently programming an OCaml module defining a type corresponding to a CPU register.
I have received few WSDLs and XSD defining a service that I need to
I'm new to Django and currently defining an existing database scheme as a Django

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.