Page view counter
how do you use TemplateBinding with a Width(double) property with a "*" or "Auto" on a new DependencyProperty? Subscribe to this thread
Last post 10-08-2008 10:51 PM by xsirxx. 4 replies.
Sort Posts:
10-06-2008 4:48 PM
how do you use TemplateBinding with a Width(double) property with a "*" or "Auto" on a new DependencyProperty?

 I have a control that has a DependencyProperty that sets a width.  It is a double so setting actual values works just fine.  But my problem is I want to be able to set percentages and Auto but I am bombing out on it.... here is the code, the property is PanelWidth...

 

 

 

// other control code

public static readonly DependencyProperty PanelWidthProperty = DependencyProperty.Register("PanelWidth", typeof(double), typeof(SomeControl), null);
public double PanelWidth
{
get { return (double)GetValue(PanelWidthProperty); }
set { SetValue(PanelWidthProperty, value); }
}
// other control code 

  

  

<!-- in generic.xaml -->

<Style TargetType="cyc:SomeControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="cyc:SomeControl">
<Grid x:Name="RootElement">
<Canvas x:Name="PanelElement" Width="{TemplateBinding PanelWidth}">
</Canvas>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

 

I set 'PanelElement's Width == PanelWidth.  This is fine if the PanelWidth is an actual number but not Auto(NaN) or %s....  So my question is, how do I properly create the DependencyProperty or PanelWidth property to allow for NaNs or %s?

 

Thanks much!

--Brad

xsirxx

Loading...
Joined on 04-28-2008
Posts 33
10-07-2008 12:06 PM
Re: how do you use TemplateBinding with a Width(double) property with a "*" or "Auto" on a new DependencyProperty?

 *shameless bump*

 

To go into more depth incase I worded the quesstion badly(which I normally do), Say I were to add this line in the xaml:

<!-- in generic.xaml -->

<Style TargetType="cyc:SomeControl">
<Setter Property="PanelWidth" Value="Auto"/> 
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="cyc:SomeControl">
                    <Grid x:Name="RootElement">
                        <Canvas x:Name="PanelElement" Width="{TemplateBinding PanelWidth}">
                        </Canvas>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

  

The line "<Setter Property="PanelWidth" Value="Auto"/>" will not work because of PanelWidth being a double.... is there a way to create a custom property and set it as Auto?

Thanks again,

Brad

xsirxx

Loading...
Joined on 04-28-2008
Posts 33
10-08-2008 5:57 AM
Marked as Answer
Re: how do you use TemplateBinding with a Width(double) property with a &quot;*&quot; or &quot;Auto&quot; on a new DependencyProperty?

Hello, the problem is, Canvas does not respect to Auto size. Try to use a Grid instead of Canvas. If you need percentage size, you can't use double. You need to use the GridLength type.

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Yi-Lun Luo - MSFT

Loading...
Joined on 10-29-2007
Posts 2,747
10-08-2008 8:48 AM
Re: how do you use TemplateBinding with a Width(double) property with a &quot;*&quot; or &quot;Auto&quot; on a new DependencyProperty?

 Hi xsirxx,

there is optiong to set width to auto you can use

like

double PanelWidth = double.NAN;

 

Mr. Sanjay S. Kadam
(Jr. Software Developer)
[AksTech Solutions Pvt Ltd.]

Mark it as answer if its helpful for you.

sanjay_sk16

Loading...
Joined on 03-01-2008
Thane
Posts 79
10-08-2008 10:51 PM
Re: how do you use TemplateBinding with a Width(double) property with a &quot;*&quot; or &quot;Auto&quot; on a new DependencyProperty?

 PERFECT Yi-Lun Luo!  That should work great!  You always know the answers!

 

Thanks very much,

Brad

xsirxx

Loading...
Joined on 04-28-2008
Posts 33
Microsoft Communities