【发布时间】:2011-01-26 14:14:41
【问题描述】:
首先让我说我是 Silverlight 的新手。但我已经弄清楚了大部分“基本”Silverlight 的东西。我目前正在使用 Silverlight 3。
简而言之,我没有看到在 UserControl 中调用了 IValueConverter。但与许多事情一样,事情并不是那么简单。 UserControl 位于 DataGrid 单元格中,其 DataColumnTemplate 在运行时由 XAML 生成。
这是我的列数据模板:
StringBuilder CellTemp = new StringBuilder();
CellTemp.Append("<DataTemplate ");
CellTemp.Append("xmlns:aa='clr-namespace:InvTech.AA.Silverlight.UI;assembly=AASilverlight' ");
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
CellTemp.Append(">");
CellTemp.AppendFormat("<aa:ProductAssetView DataContext='{{Binding Products[{0}]}}' />", index);
CellTemp.Append("</DataTemplate>");
return CellTemp.ToString();
因此,单元格的内容将绑定到我的 UserControl。这行得通;我只是无法调用我的 IValueConverter 来按照我想要的方式格式化 UserControl 的内容。
UserControl XAML 的操作部分:
(声明前缀)
xmlns:aaConv="clr-namespace:InvTech.AA.Silverlight.Core;assembly=AA.Core"
(网格布局内的绑定控件)
<TextBox x:Name="txtSAA" Grid.Row="0" Grid.Column="0" Text="{Binding SAA, Converter={StaticResource PercentConverter}, Mode=TwoWay}" Width="35" FontSize="9"/>
<TextBox x:Name="txtOVR" Grid.Row="0" Grid.Column="1" Text="{Binding Overlay, Converter={StaticResource PercentConverter}, Mode=TwoWay}" Width="35" FontSize="9" />
<TextBox x:Name="txtTAA" Grid.Row="0" Grid.Column="2" Text="{Binding TAA, Converter={StaticResource PercentConverter}, Mode=TwoWay}" Width="35" FontSize="9" />
<TextBlock x:Name="tbkCurrent" Grid.Row="0" Grid.Column="3" Text="TODO" Width="35" FontSize="9" />
<Grid.Resources>
<aaConv:PercentValueConverter x:Key="PercentConverter" />
</Grid.Resources>
这里有什么明显的错误吗?动态 XAML 是一个因素吗?与动态 XAML 模板相比,我觉得这应该是微不足道的......
谢谢
【问题讨论】:
标签: data-binding silverlight-3.0