0
首先讓我說我是Silverlight的新手。但我有大部分「基本」的Silverlight東西。目前我正在使用Silverlight 3。Silverlight 3 IValueConverter麻煩
簡而言之,我沒有看到在UserControl中調用的IValueConverter。但與許多事情一樣,這並不那麼簡單。 UserControl位於DataGrid單元格中的一列中,該列的DataColumnTemplate由XAML在運行時生成。
這裏是我的專欄的DataTemplate:
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();
所以單元格的內容越來越綁定到我的用戶控件。這有效;我無法讓我的IValueConverter調用以我想要的方式格式化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模板是微不足道的......
感謝