GuOrg / Gu.Wpf.NumericInput

MIT License
73 stars 20 forks source link

Select namespace is not recognized #45

Open valimaties opened 3 years ago

valimaties commented 3 years ago

Hi. I'm a newbie in WPF. Can you tell me why VS it tells me that SelectAllOnGotKeyboardFocus is not recognized?

<UserControl x:Class"..."
             xmlns:ni="http://gu.se/NumericInput"
             xmlns:sel="http://gu.se/Select"
             > 
    ...
    ...
                              <!-- Here it tells me that Attachable property was not found in type TextBox -->
    <StackPanel x:Name="MySP" sel:TextBox.SelectAllOnGotKeyboardFocus="True"> 
        <ni:IntBox ........ />
    </StackPanel>
    ...
</UserControl>

My project is built as .Net 5 project. Does it matter? It does not tells me that is incompatible!

Thanks!

JohanLarsson commented 3 years ago

I think this may be a bug in the WPF designer, does it work when you run the application? If you are new to WPF sadly one thing to learn is that the designer is full of false warnings. Many developers disable it altogether and write xaml using text editor only.

Please report back if it works as intended when you run the app, if so I don't think there is much we can do about it.

valimaties commented 3 years ago

Hi Johan. It's not a warning, it's an error. I cannot compile. I use the latest VS preview version, if matters 🙁 I found a workaround, by using GotFocus event, till I figure out what's going on.

PS: also, the designer crushes a lot... I will temporary delete this library to see if it is something wit it or it's from VS 🙁 very annoying

JohanLarsson commented 3 years ago

Try clone and build this: https://github.com/JohanLarsson/SelectOnFocusRepro I get some false errors but it builds and runs fine.

About how we can fix this it may be tricky if it is a bug in the designer.

I tried explicit fully qualified but still getting the error. xmlns:select="clr-namespace:Gu.Wpf.NumericInput.Select;assembly=Gu.Wpf.NumericInput"

One thing we could try is deprecate this API and add a new class

public static class Select
{
    attached property AllOnKeyboardFocus
}

Changing class name could potentially make the designer less confused.

valimaties commented 3 years ago

I tried your solution. Indeed, it work, as it compile and run app, but still get that strange error. Did you opened a ticked on Microsoft's developers community?

Thanks!

JohanLarsson commented 3 years ago

I did not open a ticket, if you feel like doing it feel free to use the repro linked above,