Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PortableColorPicker in DataGridCell: Can't switch between primary to secondary color #33

Open
Kruemelino opened this issue Aug 6, 2022 · 5 comments

Comments

@Kruemelino
Copy link

Kruemelino commented Aug 6, 2022

Hi,

thank you for your work.

I've added a PortableColorPicker to a DataGridTemplateColumn of a DataGrid. Everything looks fine so far, but I can't switch between the primary and secondary colors.

What am I doing wrong? If I use the PortableColorPicker outside of the DataGrid, the switch between the colors is possible. Even if I add the StandardColorPicker into the DataGridTemplateColumn everything is ok.

Here is my example:

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfAppTest"
        xmlns:cp="clr-namespace:ColorPicker;assembly=ColorPicker"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Window.Resources>
        <XmlDataProvider x:Key="MockList" XPath="/MockObjects/*" >
            <x:XData >
                <MockObjects xmlns="">
                    <MockObject />
                </MockObjects>
            </x:XData>
        </XmlDataProvider>
    </Window.Resources>

    <Grid DataContext="{Binding Source={StaticResource MockList}}">
        <DataGrid ItemsSource="{Binding Mode=Default, XPath=/MockObjects/MockObject}" 
                  AutoGenerateColumns="False">
            
            <DataGrid.Columns>

                <DataGridTemplateColumn Header="PortableColorPicker">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <cp:PortableColorPicker ShowAlpha="True" Height="14"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

                <DataGridTemplateColumn Header="StandardColorPicker">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <cp:StandardColorPicker ShowAlpha="True" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>

            </DataGrid.Columns>
        </DataGrid>

    </Grid>
</Window>

Thank you für your help

Addition:
The selected items will not work in this case.
image

@JellyBitz
Copy link

JellyBitz commented Sep 12, 2022

I'm experiencing exactly the same issue described, (NET 4.8).

I can't see anything out of place:

<colorpicker:PortableColorPicker
    Width="40" Height="20"
    Margin="5 2"
    Name="ColorPicker"
    ColorState="{Binding Color, Mode=TwoWay, Delay=20}"
    ShowAlpha="{Binding ShowAlpha}"
    UseHintColor="True" HintColor="Transparent"
    ToolTip="{Binding ElementName=ColorPicker,Path=HintColor}"
/>

Not sure if I'll have to use the source code directly to find out what's happening.

Edit: Forgot to mention that my issue is happening inside node from TreeView control.

@JellyBitz
Copy link

It was something to do with the Focus happening inside ListView/ListBox and all sort controls like that.

My solution at the moment, is about overriding the style from their items, or the item you're working on. At my case a Treeview so it would looks like :

<TreeView.ItemContainerStyle>
    <Style TargetType="{x:Type TreeViewItem}">
        <Setter Property="Focusable" Value="false"/>
    </Style>
</TreeView.ItemContainerStyle>

@Kruemelino
Copy link
Author

hi.

I looked at your solution. It also works in the DataGrid.

<DataGrid.CellStyle>
    <Style TargetType="{x:Type DataGridCell}">
        <Setter Property="Focusable" Value="False"/>
    <Style>
</DataGrid.CellStyle>

In the meantime I have created another solution using ItemsControl. The popup works in its ItemTemplate.
In addition, I developed my own implementation of the PortableColorPicker. The PrimaryColor and SecondaryColor are displayed.

image

@flabbet
Copy link
Member

flabbet commented Sep 14, 2022

Hi, sorry for not responding, we'll take a look at that. Thanks for investigation!

@JellyBitz
Copy link

The solution given didn't work on my treeview after all. I find out my issue is about Popup focus used into a TreeView.

So the other way around (after reading it was something to do with WPF bugs) end up like this:

PortableColorPicker.xaml

...
<popup PreviewLostKeyboardFocus="FixPopup_PreviewLostKeyboardFocus" ... >
...

PortableColorPicker.cs

private void FixPopup_PreviewLostKeyboardFocus(object sender, System.Windows.Input.KeyboardFocusChangedEventArgs e)
{
    if (e.NewFocus is System.Windows.Controls.TreeViewItem)
    {
        if (popup.IsOpen)
            e.Handled = true;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants