它是一個控制行爲。這樣可以使代碼通過下面的代碼
實現這一
XAML:
<syncfusion:SplitButton x:Name="Font_FontColor" Height="24"
DataContext="{Binding ElementName=Font_FontColorPicker}">
<syncfusion:ColorPickerPalette x:Name="Font_FontColorPicker"
syncfusion:SkinStorage.VisualStyle="Metro"
BlackWhiteVisibility="Both" IsExpanded="True" MoreColorOptionVisibility="Collapsed"
Color="Red" />
C#:
public partial class MainWindow : Window
{
bool CanHookEvents = true;
public MainWindow()
{
InitializeComponent();
Font_FontColorPicker.ColorChanged += Font_FontColorPicker_ColorChanged;
//Font_FontColor.IsDropDownOpenChanged += Font_FontColor_IsDropDownOpenChanged;
Font_FontColorPicker.Loaded += Font_FontColorPicker_Loaded;
}
private void Font_FontColorPicker_Loaded(object sender, RoutedEventArgs e)
{
if (CanHookEvents)
{
foreach (ColorGroupItem item in FindVisualChildrenOfType<ColorGroupItem>(Font_FontColorPicker))
{
if (item != null)
{
item.PreviewMouseLeftButtonDown += item_PreviewMouseLeftButtonDown;
}
}
}
}
void item_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if(Font_FontColorPicker.Color.Equals((((sender as ColorGroupItem).Color) as SolidColorBrush).Color))
{
// I have closed dropdown. Do your stuff here
Font_FontColor.IsDropDownOpen = false;
}
}
public static IEnumerable<T> FindVisualChildrenOfType<T>(DependencyObject parent)
where T : DependencyObject
{
List<T> foundChildren = new List<T>();
int childCount = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < childCount; i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
T childType = child as T;
if (childType == null)
{
foreach (var other in FindVisualChildrenOfType<T>(child))
yield return other;
}
else
{
yield return (T)child;
}
}
}
void Font_FontColorPicker_ColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Font_FontColor.IsDropDownOpen = false;
}
}
我可以問你爲什麼要這樣?這是控制的默認行爲,因爲選擇沒有改變 – Muds
對於我的控制面臨一個小問題。例如:在Ms-有填充顏色。 – Vinothkumar
所以,如果我不開火的事件,我怎麼關閉顏色選擇器的下拉按鈕。我知道它的顏色選擇器行爲。我問任何其他方式來實現我的要求。 – Vinothkumar