reference a double resource inside another double resource
I would like to reference a resource of Double inside another Double resource, something like this:
<sys:Double x:Key="width">100</sys:Double>
<sys:Double x:Key="height">{Static开发者_如何学编程Resource width}</sys:Double>
How can I do this?
I doubt that this is possible, you are referencing an atomic data-type that can contain nothing else than a numeric value which is neither a field nor a property. To allow that you probably need to create your own datatype.
Edit: Normally you should be able to use a DynamicResource
for this:
<DynamicResource x:Key="height" ResourceKey="width"/>
(Visual Studio won't like this but it should compile and work)
Well, i'm not sure the example you're giving could work, since i'm not able to do a binding to "sys:Double".
but other than that, the answer to you question: you can use a convertor, and it's pretty simple. add this class:
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();
}
}
and than reference this class in the xaml (make sure to use the xmlns of your project first):
<local:DoubleConvertor x:Key="DoubleConvertor" />
now in your binding you can do something like:
<UserControl Height="{Binding path={StaticResource width}, Converter={StaticResource DoubleConvertor} />
精彩评论