我正在开发一个时尚的 ColorPicker Control,它运行良好,但我在重新初始化时遇到了问题。
我有一个叫做 BaseBrushes 的 DP,女巫看起来像这样
public ObservableCollection<Brush> BaseBrushes
{
get { return (ObservableCollection<Brush>)GetValue(BaseBrushesProperty); }
set { SetValue(BaseBrushesProperty, value); }
}
// Using a DependencyProperty as the backing store for BaseBrushes. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BaseBrushesProperty =
DependencyProperty.Register("BaseBrushes", typeof(ObservableCollection<Brush>), typeof(ColorPicker), new UIPropertyMetadata(new ObservableCollection<Brush>()));
在 XAML 网站上,我这样设置
<gc:ColorPicker Margin="0,15,0,0" SelectedBrush="#FF1E65C4" PaletteSize="6" StepSize="25">
<gc:ColorPicker.BaseBrushes>
<SolidColorBrush Color="Red"/>
<SolidColorBrush Color="Blue"/>
<SolidColorBrush Color="Orange"/>
<SolidColorBrush Color="Green"/>
<SolidColorBrush Color="Yellow"/>
<SolidColorBrush Color="Black"/>
<SolidColorBrush Color="White"/>
</gc:ColorPicker.BaseBrushes>
</gc:ColorPicker>
我现在的问题是,每次我使用该 ColorPicker 打开一个窗口时,它都会将所有画笔再次添加到列表中,所以在第二个视图中我有 14 种颜色而不是 7 种。
我可以在 BeginInit() 方法中清除 List,但我认为这不是一个正确的解决方案。我认为这种行为是不正常的,所以我没有看到任何东西。
请如果有人知道一些事情,请帮助我
向迪玛致以最诚挚的问候