2015-06-29 72 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 }; ...