ie1*_*ie1 5 wpf resources xaml
我想在另一个 Double 资源中引用 Double 资源,如下所示:
<sys:Double x:Key="width">100</sys:Double>
<sys:Double x:Key="height">{StaticResource width}</sys:Double>
我怎样才能做到这一点?
好吧,我不确定您给出的示例是否有效,因为我无法绑定到“sys:Double”。
但除此之外,你的问题的答案是:你可以使用转换器,而且非常简单。添加这个类:
class DoubleConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
然后在 xaml 中引用此类(确保首先使用项目的 xmlns):
<local:DoubleConvertor x:Key="DoubleConvertor" />
Run Code Online (Sandbox Code Playgroud)
现在在您的绑定中您可以执行以下操作:
<UserControl Height="{Binding path={StaticResource width}, Converter={StaticResource DoubleConvertor} />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1419 次 |
| 最近记录: |