Parámetro del convertidor de encuadernación
¿Hay una manera en que podría hacer esto en un Style
:
<Style TargetType="FrameworkElement">
<Setter Property="Visibility">
<Setter.Value>
<Binding Path="Tag"
RelativeSource="{RelativeSource AncestorType=UserControl}"
Converter="{StaticResource AccessLevelToVisibilityConverter}"
ConverterParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Tag}" />
</Setter.Value>
</Setter>
</Style>
Simplemente necesito enviar el Tag
del padre de nivel superior y el Tag
del propio control a mi clase de convertidor.
2 answers
La propiedad ConverterParameter
no se puede enlazar porque no es una propiedad de dependencia.
Dado que Binding
no se deriva de DependencyObject
ninguna de sus propiedades pueden ser propiedades de dependencia. Como consecuencia, un Enlace nunca puede ser el objeto objetivo de otro Enlace.
Sin embargo, Hay una solución alternativa. Podrías usar un MultiBinding
con un convertidor de múltiples valores en lugar de un enlace normal:
<Style TargetType="FrameworkElement">
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource AccessLevelToVisibilityConverter}">
<Binding Path="Tag" RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType=UserControl}"/>
<Binding Path="Tag" RelativeSource="{RelativeSource Mode=Self}"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
El convertidor de múltiples valores obtiene una matriz de valores de origen como entrada:
public class AccessLevelToVisibilityConverter : IMultiValueConverter
{
public object Convert(
object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.All(v => (v is bool && (bool)v))
? Visibility.Visible
: Visibility.Hidden;
}
public object[] ConvertBack(
object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-23 06:20:06
No, desafortunadamente esto no será posible porque ConverterParameter
no es un DependencyProperty
por lo que no podrá usar enlaces
Pero quizás podrías hacer trampa y usar un MultiBinding
con IMultiValueConverter
para pasar las 2 propiedades Tag
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-30 22:57:53