<TextBlock Text="{Binding Path=[0]} />
<TextBlock Text="{Binding Path=[myKey]} />
funciona bien. Pero, ¿hay alguna manera de pasar una variable como clave del indexador?
<TextBlock Text="{Binding Path=[{Binding Column.Index}]} />
<TextBlock Text="{Binding Path=[0]} />
<TextBlock Text="{Binding Path=[myKey]} />
funciona bien. Pero, ¿hay alguna manera de pasar una variable como clave del indexador?
<TextBlock Text="{Binding Path=[{Binding Column.Index}]} />
Esto exige un
IValueConverter
IMultiValueConverter
.
¿De verdad? ¿Puedes describir cómo harías esto con un convertidor de valor? – ColinE
No, me temo que no. En este punto, probablemente debas considerar la posibilidad de crear un modelo de vista que dé forma a tus datos para facilitar su vinculación.
La forma más rápida de manejar esto es por lo general a utilizar un MultiBinding con un IMultiValueConverter que acepta la recopilación y el índice de sus consolidaciones:
<TextBlock.Text>
<MultiBinding Converter="{StaticResource ListIndexToValueConverter}">
<Binding /> <!-- assuming the collection is the DataContext -->
<Binding Path="Column.Index"/>
</MultiBinding>
</TextBlock.Text>
el convertidor lo puede hacer la búsqueda en base a los dos valores como esto:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length < 2)
return Binding.DoNothing;
IList list = values[0] as IList;
if (list == null || values[1] == null || !(values[1] is int))
return Binding.DoNothing;
return list[(int)values[1]];
}
enlace de MSDN para futuros buscadores: http://msdn.microsoft.com/en-us/library/ms742451.aspx – yzorg
Compruebe mi respuesta en este enlace http://stackoverflow.com/q/ 4385693/217880 – biju