Merge pull request #4730 from HavenDV/fix-color-picker-button-binding-issue

fix: Fix color picker button binding failure issue
This commit is contained in:
Michael Hawker MSFT (XAML Llama) 2022-10-18 10:25:10 -07:00 коммит произвёл GitHub
Родитель acf30d6d46 7f49e981db
Коммит 5d901493fc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 38 добавлений и 1 удалений

Просмотреть файл

@ -44,6 +44,7 @@
<localconverters:ColorToColorShadeConverter x:Key="ColorToColorShadeConverter" />
<converters:ColorToDisplayNameConverter x:Key="ColorToDisplayNameConverter" />
<localconverters:ColorToHexConverter x:Key="ColorToHexConverter" />
<localconverters:ColorToSelectedValueConverter x:Key="ColorToSelectedValueConverter" />
<Style x:Key="InputTextBoxStyle"
TargetType="TextBox">
@ -157,7 +158,7 @@
Padding="0"
ItemContainerStyle="{StaticResource PaletteGridViewItemStyle}"
ItemsSource="{TemplateBinding CustomPaletteColors}"
SelectedValue="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Color, Mode=TwoWay}"
SelectedValue="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Color, Mode=TwoWay, Converter={StaticResource ColorToSelectedValueConverter}}"
SelectionMode="Single"
Tag="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Color, Mode=OneWay}">
<GridView.ItemsPanel>

Просмотреть файл

@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
namespace Microsoft.Toolkit.Uwp.UI.Controls.ColorPickerConverters
{
/// <summary>
/// Ignores null target values for TwoWay binding.
/// </summary>
public class ColorToSelectedValueConverter : IValueConverter
{
/// <inheritdoc/>
public object Convert(
object value,
Type targetType,
object parameter,
string language)
{
return value;
}
/// <inheritdoc/>
public object ConvertBack(
object value,
Type targetType,
object parameter,
string language)
{
return value ?? DependencyProperty.UnsetValue;
}
}
}