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:
Коммит
5d901493fc
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче