我使用Silverlight 3的開發,我有下面的XAML代碼:組合框使用DoubleCollection結合拋出ArgumentException的
<Application.Resources>
<DataTemplate x:Key="LineCombo">
<StackPanel Orientation="Horizontal" Margin="2">
<Line X1="0" Y1="0" X2="50" Y2="0" VerticalAlignment="Center" Stroke="Blue" StrokeThickness="1" StrokeDashArray="{Binding}" />
</StackPanel>
</DataTemplate>
</Application.Resources>
<StackPanel>
<ComboBox x:Name="ComboBoxTest1" ItemTemplate="{StaticResource LineCombo}" Width="200" Height="30">
</ComboBox>
<ComboBox x:Name="ComboBoxTest2" ItemTemplate="{StaticResource LineCombo}" Width="200" Height="30">
</ComboBox>
</StackPanel>
而後面的代碼:
public ObservableCollection<DoubleCollection> strokeDashArrays1 = new ObservableCollection<DoubleCollection>();
public ObservableCollection<Double[]> strokeDashArrays2 = new ObservableCollection<Double[]>();
public MainPage()
{
InitializeComponent();
strokeDashArrays1.Add(new DoubleCollection { 2, 4 });
strokeDashArrays1.Add(new DoubleCollection { 3, 6 });
strokeDashArrays1.Add(new DoubleCollection { 4, 8 });
strokeDashArrays2.Add(new double[] { 2, 4 });
strokeDashArrays2.Add(new double[] { 3, 6 });
strokeDashArrays2.Add(new double[] { 4, 8 });
ComboBoxTest1.ItemsSource = strokeDashArrays1;
ComboBoxTest2.ItemsSource = strokeDashArrays2;
}
選擇從ComboBoxTest1項目引發ArgumentException:
「價值不在 預期範圍內」。
當選擇一個項目時,都顯示OK和ComboBoxTest2工作正常。
是什麼導致了這種行爲?
我只使用了Silverlight幾個星期,並試圖顯示一個StrokeDashArrays組合框來允許行自定義。