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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With