Windows Vista Forums

How to get Size of parent in a template
  1. #1


    Sam Jost Guest

    How to get Size of parent in a template

    I've created my own Template for a TextBox so I can draw a custom
    border.
    The initial size of the TextBox I can bind to without problems using
    something like

    <PathFigure StartPoint="{Binding ElementName=Label, Path=RenderSize,
    Converter={StaticResource sizeToPoint}}">

    Only problem is: when the size of the TextBox does change for whatever
    reason, my custom border's size stays the same. The border does not
    reflect the changes of the size of the TextBox.

    My guess is I need to get the size in a different way, but I don't know
    where to get it. And I can't use Rectangle, or Border to just fill the
    border since these two can't draw what I need.

    Anyone got an idea how to bind to the size of a control so my template
    does grow and shrink with it?

    Thanks,
    Sam




      My System SpecsSystem Spec

  2. #2


    Suresh Guest

    Re: How to get Size of parent in a template

    Hey Sam,

    Try binding to ActualHeight and ActualWidth of the TextBox instead
    of RenderSize.


    Sam Jost wrote:
    > I've created my own Template for a TextBox so I can draw a custom
    > border.
    > The initial size of the TextBox I can bind to without problems using
    > something like
    >
    > <PathFigure StartPoint="{Binding ElementName=Label, Path=RenderSize,
    > Converter={StaticResource sizeToPoint}}">
    >
    > Only problem is: when the size of the TextBox does change for whatever
    > reason, my custom border's size stays the same. The border does not
    > reflect the changes of the size of the TextBox.
    >
    > My guess is I need to get the size in a different way, but I don't know
    > where to get it. And I can't use Rectangle, or Border to just fill the
    > border since these two can't draw what I need.
    >
    > Anyone got an idea how to bind to the size of a control so my template
    > does grow and shrink with it?
    >
    > Thanks,
    > Sam



      My System SpecsSystem Spec

  3. #3


    Sam Jost Guest

    Re: How to get Size of parent in a template

    Suresh,

    These two look great! I could bind to ActualWidth or ActualHeight and
    all sizes get updated just like I'd like them to.

    But how do I bind to both of them at once? Writing a converter is easy,
    but in the binding I have to decide for ActualHeight or ActualWidth, I
    can't have them both at once

    I tried to bind them like

    <LineSegment>
    <LineSegment.Point>
    <Point
    X="{Binding RelativeSource={RelativeSource TemplatedParent},
    Path=ActualWidth"}"
    Y="{Binding RelativeSource={RelativeSource TemplatedParent},
    Path=ActualHeight"}"
    </LineSegment.Point>
    </LineSegment>

    but I only get an error message saying I cant attack a binding to the
    double 'X'

    How do I bind to both at once??

    Thanks a lot,
    Sam


    Suresh schrieb:

    > Hey Sam,
    >
    > Try binding to ActualHeight and ActualWidth of the TextBox instead
    > of RenderSize.
    >
    >
    > Sam Jost wrote:
    > > I've created my own Template for a TextBox so I can draw a custom
    > > border.
    > > The initial size of the TextBox I can bind to without problems using
    > > something like
    > >
    > > <PathFigure StartPoint="{Binding ElementName=Label, Path=RenderSize,
    > > Converter={StaticResource sizeToPoint}}">
    > >
    > > Only problem is: when the size of the TextBox does change for whatever
    > > reason, my custom border's size stays the same. The border does not
    > > reflect the changes of the size of the TextBox.
    > >
    > > My guess is I need to get the size in a different way, but I don't know
    > > where to get it. And I can't use Rectangle, or Border to just fill the
    > > border since these two can't draw what I need.
    > >
    > > Anyone got an idea how to bind to the size of a control so my template
    > > does grow and shrink with it?
    > >
    > > Thanks,
    > > Sam



      My System SpecsSystem Spec

How to get Size of parent in a template problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting when parent is about to change Mike .NET General 9 22 Jan 2010
Parent Process ID David PowerShell 2 25 Feb 2009
Collections Help when in a parent class scott ocamb .NET General 1 17 May 2008
How to get the Parent of a TreeViewItem in a treeview when using HierchicalDataTemplate ? Pon Avalon 1 05 Apr 2007
Get parent directory Thomas Kofler PowerShell 3 23 Nov 2006