我注意到ComboBox的静态资源和动态资源之间的行为差异。 项目Source,当ComboBox从视觉树中抽出时。
- in the static exemple the selected destination remains
- in the dynamic exemple, the underlying object gets a null value
装饰似乎为科索沃,因为当 com子集中使用并改变其选择的Index时,该改动被适当通知到另一个清单——两个物体都实施认证程序,两个清单都是可观察的。
当充满活力的 com子摆脱了重点时,奇怪的事情就会发生。
<>XAML
<Window ... xmlns:me = "clr-namespace:WpfComboBoxBug">
<Window.Resources>
<me:ShippingList x:Key="sl" />
<me:DestinationList x:Key="dl" />
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="21" />
<RowDefinition Height="421*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Custom:DataGrid Grid.Row="1"
ItemsSource="{StaticResource sl}" x:Name="dg" AutoGenerateColumns="False" Grid.RowSpan="2">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Header="Reference" Binding="{Binding Reference}" />
<Custom:DataGridTemplateColumn Header="Destination">
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Destination.Name}"></TextBlock>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
<Custom:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{StaticResource dl}" SelectedItem="{Binding Destination,Mode=TwoWay}" DisplayMemberPath="Name"/>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellEditingTemplate>
</Custom:DataGridTemplateColumn>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
<Custom:DataGrid Grid.Column="1" Grid.Row="1" ItemsSource="{StaticResource sl}" x:Name="dg2" AutoGenerateColumns="False" Grid.RowSpan="2">
<Custom:DataGrid.Columns>
<Custom:DataGridTextColumn Header="Reference" Binding="{Binding Reference}" />
<Custom:DataGridTemplateColumn Header="Destination">
<Custom:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Destination.Name}"></TextBlock>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellTemplate>
<Custom:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{DynamicResource dynamicdl}" SelectedItem="{Binding Destination,Mode=TwoWay}" DisplayMemberPath="Name"/>
</DataTemplate>
</Custom:DataGridTemplateColumn.CellEditingTemplate>
</Custom:DataGridTemplateColumn>
</Custom:DataGrid.Columns>
</Custom:DataGrid>
<TextBox Height="23" Name="textBox1" VerticalAlignment="Top" Text="Static" />
<TextBox Height="23" Name="textBox2" VerticalAlignment="Top" Text="Dynamic" Grid.Column="2" />
</Grid>
</Window>
<<>CS>。
using System;
/* snip */
namespace WpfComboBoxBug
{
/// <summary>
/// Logique d interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
ShippingList sl;
this.InitializeComponent();
sl = this.Resources["sl"] as ShippingList;
ResourceDictionary rd = new ResourceDictionary();
rd.Add("dynamicdl", this.FindResource("dl"));
dg2.Resources = rd;
dg.ItemsSource = CollectionViewSource.GetDefaultView(sl);
dg2.ItemsSource = CollectionViewSource.GetDefaultView(sl);
}
}
}
http://dl.free.fr/eI1VtkaB8“rel=“nofollow noreferer” http://dl.free.fr/eI1VtkaB8 (VS 2008 SP1, NET SP 3.51 )
我期望这一动态资源与这一情况下的静态资源一样,在一开始就将它彻底化了。
- Have I found a bug here ?
- If that not the case, how would you explain the difference ?