Ala*_*ain 3 c# wpf xaml .net-4.0
我正在尝试在我的xaml中定义一个本地资源,它应该是我的单元格的宽度,所以不要去:
<Setter Property="ColumnStretchMinWidth" Value="75"/>
<Textbox Width="75" />
<ColumnDefinition Width="*" MinWidth="75" />
...etc
Run Code Online (Sandbox Code Playgroud)
我可以去
<Setter Property="ColumnStretchMinWidth" Value="{StaticResource MinCellWidth}"/>
<Textbox Width="{StaticResource MinCellWidth}" />
<ColumnDefinition Width="*" MinWidth="{StaticResource MinCellWidth}" />
Run Code Online (Sandbox Code Playgroud)
但是当我定义这个常量时,我会遇到绑定错误,说它无法转换.我走的时候
<System:String x:Key="MinCellWidth">"75"</s:String>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,说某些控件无法从String转换为Double.我走的时候
<System:Double x:Key="MinCellWidth">"75"</s:Double>
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,说它不能从Double转换为字符串用于其他控件(比如ColumnDefinition,其中允许使用"*"宽度).
什么是硬编码的神奇类型="75"
,可以将其转换为每个控件的适当类型.如何定义可在所有这些不同位置使用的资源?
ColumnDefinition.Width的神奇类型是GridLength,它需要该类型的资源.就像TextBox.Width需要一个double.
<s:Double x:Key="minCellWidth">55</s:Double>
<sw:GridLength x:Key="minGridWidth">55</sw:GridLength>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1281 次 |
最近记录: |