in dev/ColorPicker/ColorPicker.cpp [24:256]
void ColorPicker::OnApplyTemplate()
{
winrt::IControlProtected thisAsControlProtected = *this;
m_colorSpectrum.set(GetTemplateChildT<winrt::ColorSpectrum>(L"ColorSpectrum", thisAsControlProtected));
m_colorPreviewRectangleGrid.set(GetTemplateChildT<winrt::Grid>(L"ColorPreviewRectangleGrid", thisAsControlProtected));
m_colorPreviewRectangle.set(GetTemplateChildT<winrt::Rectangle>(L"ColorPreviewRectangle", thisAsControlProtected));
m_previousColorRectangle.set(GetTemplateChildT<winrt::Rectangle>(L"PreviousColorRectangle", thisAsControlProtected));
m_colorPreviewRectangleCheckeredBackgroundImageBrush.set(GetTemplateChildT<winrt::ImageBrush>(L"ColorPreviewRectangleCheckeredBackgroundImageBrush", thisAsControlProtected));
m_thirdDimensionSlider.set(GetTemplateChildT<winrt::ColorPickerSlider>(L"ThirdDimensionSlider", thisAsControlProtected));
m_thirdDimensionSliderGradientBrush.set(GetTemplateChildT<winrt::LinearGradientBrush>(L"ThirdDimensionSliderGradientBrush", thisAsControlProtected));
m_alphaSlider.set(GetTemplateChildT<winrt::ColorPickerSlider>(L"AlphaSlider", thisAsControlProtected));
m_alphaSliderGradientBrush.set(GetTemplateChildT<winrt::LinearGradientBrush>(L"AlphaSliderGradientBrush", thisAsControlProtected));
m_alphaSliderBackgroundRectangle.set(GetTemplateChildT<winrt::Rectangle>(L"AlphaSliderBackgroundRectangle", thisAsControlProtected));
m_alphaSliderCheckeredBackgroundImageBrush.set(GetTemplateChildT<winrt::ImageBrush>(L"AlphaSliderCheckeredBackgroundImageBrush", thisAsControlProtected));
m_moreButton.set(GetTemplateChildT<winrt::ButtonBase>(L"MoreButton", thisAsControlProtected));
m_colorRepresentationComboBox.set(GetTemplateChildT<winrt::ComboBox>(L"ColorRepresentationComboBox", thisAsControlProtected));
m_redTextBox.set(GetTemplateChildT<winrt::TextBox>(L"RedTextBox", thisAsControlProtected));
m_greenTextBox.set(GetTemplateChildT<winrt::TextBox>(L"GreenTextBox", thisAsControlProtected));
m_blueTextBox.set(GetTemplateChildT<winrt::TextBox>(L"BlueTextBox", thisAsControlProtected));
m_hueTextBox.set(GetTemplateChildT<winrt::TextBox>(L"HueTextBox", thisAsControlProtected));
m_saturationTextBox.set(GetTemplateChildT<winrt::TextBox>(L"SaturationTextBox", thisAsControlProtected));
m_valueTextBox.set(GetTemplateChildT<winrt::TextBox>(L"ValueTextBox", thisAsControlProtected));
m_alphaTextBox.set(GetTemplateChildT<winrt::TextBox>(L"AlphaTextBox", thisAsControlProtected));
m_hexTextBox.set(GetTemplateChildT<winrt::TextBox>(L"HexTextBox", thisAsControlProtected));
m_RgbComboBoxItem.set(GetTemplateChildT<winrt::ComboBoxItem>(L"RGBComboBoxItem", thisAsControlProtected));
m_HsvComboBoxItem.set(GetTemplateChildT<winrt::ComboBoxItem>(L"HSVComboBoxItem", thisAsControlProtected));
m_redLabel.set(GetTemplateChildT<winrt::TextBlock>(L"RedLabel", thisAsControlProtected));
m_greenLabel.set(GetTemplateChildT<winrt::TextBlock>(L"GreenLabel", thisAsControlProtected));
m_blueLabel.set(GetTemplateChildT<winrt::TextBlock>(L"BlueLabel", thisAsControlProtected));
m_hueLabel.set(GetTemplateChildT<winrt::TextBlock>(L"HueLabel", thisAsControlProtected));
m_saturationLabel.set(GetTemplateChildT<winrt::TextBlock>(L"SaturationLabel", thisAsControlProtected));
m_valueLabel.set(GetTemplateChildT<winrt::TextBlock>(L"ValueLabel", thisAsControlProtected));
m_alphaLabel.set(GetTemplateChildT<winrt::TextBlock>(L"AlphaLabel", thisAsControlProtected));
m_checkerColorBrush.set(GetTemplateChildT<winrt::SolidColorBrush>(L"CheckerColorBrush", thisAsControlProtected));
if (auto&& colorSpectrum = m_colorSpectrum.get())
{
colorSpectrum.ColorChanged({ this, &ColorPicker::OnColorSpectrumColorChanged });
colorSpectrum.SizeChanged({ this, &ColorPicker::OnColorSpectrumSizeChanged });
winrt::AutomationProperties::SetName(colorSpectrum, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameColorSpectrum));
}
if (auto&& colorPreviewRectangleGrid = m_colorPreviewRectangleGrid.get())
{
colorPreviewRectangleGrid.SizeChanged({ this, &ColorPicker::OnColorPreviewRectangleGridSizeChanged });
}
if (auto&& thirdDimensionSlider = m_thirdDimensionSlider.get())
{
thirdDimensionSlider.ValueChanged({ this, &ColorPicker::OnThirdDimensionSliderValueChanged });
SetThirdDimensionSliderChannel();
}
if (auto&& alphaSlider = m_alphaSlider.get())
{
alphaSlider.ValueChanged({ this, &ColorPicker::OnAlphaSliderValueChanged });
alphaSlider.ColorChannel(winrt::ColorPickerHsvChannel::Alpha);
winrt::AutomationProperties::SetName(alphaSlider, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameAlphaSlider));
}
if (auto&& alphaSliderBackgroundRectangle = m_alphaSliderBackgroundRectangle.get())
{
alphaSliderBackgroundRectangle.SizeChanged({ this, &ColorPicker::OnAlphaSliderBackgroundRectangleSizeChanged });
}
if (auto&& moreButton = m_moreButton.get())
{
if (const auto moreButtonAsToggleButton = moreButton.try_as<winrt::ToggleButton>())
{
moreButtonAsToggleButton.Checked({ this, &ColorPicker::OnMoreButtonChecked });
moreButtonAsToggleButton.Unchecked({ this, &ColorPicker::OnMoreButtonUnchecked });
}
else
{
moreButton.Click({ this, &ColorPicker::OnMoreButtonClicked });
}
winrt::AutomationProperties::SetName(moreButton, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameMoreButtonCollapsed));
winrt::AutomationProperties::SetHelpText(moreButton, ResourceAccessor::GetLocalizedStringResource(SR_HelpTextMoreButton));
if (const auto moreButtonLabel = GetTemplateChildT<winrt::TextBlock>(L"MoreButtonLabel", thisAsControlProtected))
{
m_moreButtonLabel.set(moreButtonLabel);
moreButtonLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextMoreButtonLabelCollapsed));
}
}
if (auto&& colorRepresentationComboBox = m_colorRepresentationComboBox.get())
{
colorRepresentationComboBox.SelectionChanged({ this, &ColorPicker::OnColorRepresentationComboBoxSelectionChanged });
winrt::AutomationProperties::SetName(colorRepresentationComboBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameColorModelComboBox));
}
if (auto&& redTextBox = m_redTextBox.get())
{
redTextBox.TextChanging({ this, &ColorPicker::OnRgbTextChanging });
redTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
redTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(redTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameRedTextBox));
}
if (auto&& greenTextBox = m_greenTextBox.get())
{
greenTextBox.TextChanging({ this, &ColorPicker::OnRgbTextChanging });
greenTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
greenTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(greenTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameGreenTextBox));
}
if (auto&& blueTextBox = m_blueTextBox.get())
{
blueTextBox.TextChanging({ this, &ColorPicker::OnRgbTextChanging });
blueTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
blueTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(blueTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameBlueTextBox));
}
if (auto&& hueTextBox = m_hueTextBox.get())
{
hueTextBox.TextChanging({ this, &ColorPicker::OnHueTextChanging });
hueTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
hueTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(hueTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameHueTextBox));
}
if (auto&& saturationTextBox = m_saturationTextBox.get())
{
saturationTextBox.TextChanging({ this, &ColorPicker::OnSaturationTextChanging });
saturationTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
saturationTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(saturationTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameSaturationTextBox));
}
if (auto&& valueTextBox = m_valueTextBox.get())
{
valueTextBox.TextChanging({ this, &ColorPicker::OnValueTextChanging });
valueTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
valueTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(valueTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameValueTextBox));
}
if (auto&& alphaTextBox = m_alphaTextBox.get())
{
alphaTextBox.TextChanging({ this, &ColorPicker::OnAlphaTextChanging });
alphaTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
alphaTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(alphaTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameAlphaTextBox));
}
if (auto&& hexTextBox = m_hexTextBox.get())
{
hexTextBox.TextChanging({ this, &ColorPicker::OnHexTextChanging });
hexTextBox.GotFocus({ this, &ColorPicker::OnTextBoxGotFocus });
hexTextBox.LostFocus({ this, &ColorPicker::OnTextBoxLostFocus });
winrt::AutomationProperties::SetName(hexTextBox, ResourceAccessor::GetLocalizedStringResource(SR_AutomationNameHexTextBox));
}
if (auto&& rgbComboBoxItem = m_RgbComboBoxItem.get())
{
rgbComboBoxItem.Content(box_value(ResourceAccessor::GetLocalizedStringResource(SR_ContentRGBComboBoxItem)));
}
if (auto&& hsvComboBoxItem = m_HsvComboBoxItem.get())
{
hsvComboBoxItem.Content(box_value(ResourceAccessor::GetLocalizedStringResource(SR_ContentHSVComboBoxItem)));
}
if (auto&& redLabel = m_redLabel.get())
{
redLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextRedLabel));
}
if (auto&& greenLabel = m_greenLabel.get())
{
greenLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextGreenLabel));
}
if (auto&& blueLabel = m_blueLabel.get())
{
blueLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextBlueLabel));
}
if (auto&& hueLabel = m_hueLabel.get())
{
hueLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextHueLabel));
}
if (auto&& saturationLabel = m_saturationLabel.get())
{
saturationLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextSaturationLabel));
}
if (auto&& valueLabel = m_valueLabel.get())
{
valueLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextValueLabel));
}
if (auto&& alphaLabel = m_alphaLabel.get())
{
alphaLabel.Text(ResourceAccessor::GetLocalizedStringResource(SR_TextAlphaLabel));
}
if (auto&& checkerColorBrush = m_checkerColorBrush.get())
{
checkerColorBrush.RegisterPropertyChangedCallback(winrt::SolidColorBrush::ColorProperty(), { this, &ColorPicker::OnCheckerColorChanged });
}
CreateColorPreviewCheckeredBackground();
CreateAlphaSliderCheckeredBackground();
UpdateVisualState(false /* useTransitions */);
InitializeColor();
UpdatePreviousColorRectangle();
}