2015-06-29 73 views
0

我找保持我们在应用程序中的所有RadColorPicker实例相同的近期彩色列表WPF RadColorPicker相同颜色的最近清单。即G。如果用户从一个颜色拾取(和colorEditor)控件创建一个自定义颜色,用户不必再拾色器这么做。用户应该在所有拾色器的近期颜色中看到相同的颜色。维护应用程序

我想弄清楚,如何实现它。我看到属性RecentColorsItemsSource,这可能在这里使用,但是,我无法得到它的工作。我正在尝试使用“RecentColorsItemsSource”属性来设置示例颜色,但是我遇到了运行时错误。以下是XAML代码和后台代码的代码:

的XAML:

<telerik:RadColorPicker x:Name="myColorPicker" IsRecentColorsActive="True" RecentColorsItemsSource="{Binding Path=MyColors}" /> 

代码隐藏或视图模型:

但与此代码我收到此错误:

对象未将引用设置为对象的实例。

at Telerik.Windows.Controls.RadColorSelector.BindRecentColorsPalette() 
at Telerik.Windows.Controls.RadColorSelector.BindXamlElements() 
at Telerik.Windows.Controls.RadColorSelector.OnApplyTemplate() 
at System.Windows.FrameworkElement.ApplyTemplate() 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Control.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 

这里的一些帮助是可观的。

回答

1

您可以设置IsRecentColorsActive = “真”

看到这个link

如果你要保持颜色选择器控制的多个实例之间最近的颜色,那么你必须采取的RecentColorsItemsSource Property优势。所以基本上你必须保持最近的颜色集合,并将相同的集合绑定到你想要共享最近颜色的所有颜色选择器。

+0

,当我们使用单一颜色选择器帮助。我的场景的例子是,比方说我们在网格的颜色列中使用颜色选择器,那么第一行颜色选择器的最近颜色将不会出现在第二个颜色选择器中,依此类推。 – Randeep

+0

我编辑了我的答案 – Ahmed

+0

我也探讨了同样的情况,但是在使用它时我得到了空引用异常,我无法弄清楚我在哪里得到这个。我正在使用此代码来设置此集合。 radColorPicker.RecentColorsItemsSource = new List {Colors.Red,Colors.Pink}; – Randeep

0

有点迟到了,但它可能会帮助任何人谁遇到同样的问题,像我一样。

我对RecentColorsItemsSource使用ObservableCollection<Color>取得了一些成功。 Telerik的可能蒙上RecentColorsItemsSource在内部的ObservableCollection。

尝试类似:

... MyColors = new ObservableCollection<Color> { Colors.Red, Colors.Green }; ...