Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the datatype of this width?

I'm trying to define a local resource in my xaml which is supposed to be the width of my cells, so rather than going:

<Setter Property="ColumnStretchMinWidth" Value="75"/>
<Textbox Width="75" />
<ColumnDefinition Width="*" MinWidth="75" />
...etc

I can go

<Setter Property="ColumnStretchMinWidth" Value="{StaticResource MinCellWidth}"/>
<Textbox Width="{StaticResource MinCellWidth}" />
<ColumnDefinition Width="*" MinWidth="{StaticResource MinCellWidth}" />

But when I define this constant, I get binding errors saying it can't cast. When I go

<System:String x:Key="MinCellWidth">"75"</s:String>

I get an error saying it can't convert from String to Double for some controls. When I go

<System:Double x:Key="MinCellWidth">"75"</s:Double>

I get an error saying it can't convert from Double to string for other controls (like the ColumnDefinition, where "*" widths are allowed).

What is the magic type of the hardcoded ="75" that lets it be converted to the appropriate type for each control. How can I define a resource that can be used in all these different places?

like image 768
Alain Avatar asked Nov 04 '25 23:11

Alain


1 Answers

The magic type of ColumnDefinition.Width is GridLength, and it needs a resource of that type. Just as TextBox.Width needs a double.

<s:Double x:Key="minCellWidth">55</s:Double>
<sw:GridLength x:Key="minGridWidth">55</sw:GridLength>
like image 137
erikH Avatar answered Nov 07 '25 11:11

erikH