我使用
DataGrid
和
ColorPickerButton
从这里
xmlns:toolkit="using:Microsoft.Toolkit.Uwp.UI.Controls
当我点击
颜色选择器按钮
它保持打开状态,颜色特性不变。
如何修复?
非常感谢。
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
它看起来像一个虫子。。。
因此,当你在第一个选项卡中选择颜色时,不会发生任何事情,但如果在其他选项卡上也这样做,它会起作用,并且可以成功地选择颜色。