UWP DataGrid 单元格中的 UWP ColorPickerButton 不会被选中

UWP ColorPickerButton in UWP DataGrid cell won't be selected

我从这里使用 DataGridColorPickerButton

xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls

当我点击 ColorPickerButton 它保持打开状态并且颜色 属性 没有改变。

如何解决? 谢谢!

XAML

 <toolkit:DataGrid    
                    x:Name="dataGridLayers"
                    Margin="0,0,0,0"
                    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
                    HorizontalScrollBarVisibility="Visible"
                    VerticalScrollBarVisibility="Visible"
                    AlternatingRowBackground="Transparent" 
                    AreRowDetailsFrozen="False"
                    AreRowGroupHeadersFrozen="True"
                    AutoGenerateColumns="False"
                    CanUserSortColumns="False"
                    CanUserReorderColumns="True"
                    RowGroupHeaderPropertyNameAlternative=""
                    CanUserResizeColumns="True"
                    ColumnHeaderHeight="32"
                    MaxColumnWidth="400"
                    FrozenColumnCount="0"
                    GridLinesVisibility="None"
                    HeadersVisibility="Column"
                    IsReadOnly="False" 
                    Height="400"
                    RowDetailsVisibilityMode="Collapsed"
                    SelectionMode="Single">
                                <toolkit:DataGrid.Columns>
                                    <toolkit:DataGridTextColumn Header="Name" Binding="{Binding LayerName}"  Tag="LayerName" IsReadOnly="True" />
                                    <toolkit:DataGridCheckBoxColumn IsThreeState="False"  Header="Включить в карту" Binding="{Binding LayerVisibility,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  Tag="LayerVisibility"  />
                                    <toolkit:DataGridTextColumn Header="Stroke" Binding="{Binding LayerStroke, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"   Tag="LayerStroke" />
                                    <toolkit:DataGridTemplateColumn  Header="Color"  Tag="LayerColor">
                                        <toolkit:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate >
                                                <toolkit:ColorPickerButton SelectedColor="{Binding LayerColor, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                                            </DataTemplate>
                                        </toolkit:DataGridTemplateColumn.CellTemplate>
                                    </toolkit:DataGridTemplateColumn>
                                </toolkit:DataGrid.Columns>
                            </toolkit:DataGrid>
                     

C#

 public abstract class EtherMapLayerBase : INotifyPropertyChanged
    {
        public Windows.UI.Color _layerColor { get; set; }
        public Windows.UI.Color LayerColor
        {
            get
            {
                return _layerColor;
            }

            set
            {
                if (_layerColor != value)
                {
                    _layerColor = value;
                    OnPropertyChanged();
                }
            }
        }


        public int _layerStroke { get; set; }
        public int LayerStroke
        {
            get
            {
                return _layerStroke;
            }

            set
            {
                if (_layerStroke != value)
                {
                    _layerStroke = value;
                    OnPropertyChanged();
                }
            }
        }


        public string _layerName { get; set; }
        public string LayerName
        {
            get
            {
                return _layerName;
            }

            set
            {
                if (_layerName != value)
                {
                    _layerName = value;
                    OnPropertyChanged();
                }
            }
        }


        public bool _layerVisibility { get; set; }
        public bool LayerVisibility
        {
            get
            {
                return _layerVisibility;
            }

            set
            {
                if (_layerVisibility != value)
                {
                    _layerVisibility = value;
                    OnPropertyChanged();
                }
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
        {
            if (object.Equals(storage, value))
            {
                return false;
            }
            else
            {
                storage = value;
                OnPropertyChanged(propertyName);
                return true;
            }
        }
    }

    public class EtherMapLayerView : EtherMapLayerBase
    {
        public EtherMapLayerView()
        {
            LayerStroke = 1;
            LayerColor = Colors.Black; // using Windows.UI;
            LayerVisibility = true;
        }
    }

更新 #1 好像是个bug...

因此,当您在第一个 TAB 中 select 着色时,没有任何反应,但如果对其他 TAB 执行相同的操作,它会起作用,并且可以成功 select 编辑颜色。

When I click on the ColorPickerButton it keeps open and no color property changed.

问题是你将底色设置为BlackLayerColor = Colors.Black,这样会导致无法选择色轮。

请尝试将默认颜色设置为 Transparent,它将按预期工作。

LayerColor = Colors.Transparent