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

attached DependencyProperty not found when declared in classlib #9177

Closed
Al-Caron opened this issue Dec 18, 2023 · 1 comment
Closed

attached DependencyProperty not found when declared in classlib #9177

Al-Caron opened this issue Dec 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Al-Caron
Copy link

Al-Caron commented Dec 18, 2023

Describe the bug

I wrote a simple attached property "AutoScrollOnSelect" in my "control classlib". The main application (WinUI 3 unpackaged app )that wants to use it can't find it :

2>D:\sources\ced\ev2557\cln\dotnet\DashCed\Pages\PagePannes.xaml(149,22): XamlCompiler error WMC0010: Unknown attachable member 'DataGridExtension.AutoScrollOnSelect' on element 'DataGrid'

image

Steps to reproduce the bug

  1. Create a WinUI3 Classlib that can contains UI classes.
  2. Create the attachedProperty
    `using CommunityToolkit.WinUI.UI.Controls;
    using Microsoft.UI.Xaml;
    using System.Linq;

namespace CGI.Ced.WinUI.Controls.Extensions;

public class DataGridExtension
{

public static readonly DependencyProperty AutoScrollOnSelectProperty = DependencyProperty.RegisterAttached("AutoScrollOnSelect", typeof(bool), typeof(DataGridExtension), new PropertyMetadata(false, OnAutoScrollOnSelectChanged));


private static void OnAutoScrollOnSelectChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    if (d is DataGrid dataGrid)
    {
        dataGrid.SelectionChanged += DataGrid_SelectionChanged;
        dataGrid.Loaded += DataGrid_Loaded;
        dataGrid.Unloaded += DataGrid_Unloaded;
    }
}

private static void DataGrid_Unloaded(object sender, RoutedEventArgs e)
{
    DataGrid dataGrid = sender as DataGrid;
    if (dataGrid != null)
    {
        dataGrid.SelectionChanged -= DataGrid_SelectionChanged;
        dataGrid.Loaded -= DataGrid_Loaded;
    }
}

private static void DataGrid_Loaded(object sender, RoutedEventArgs e)
{
    DataGrid grid = sender as DataGrid;
    if (grid != null && grid.SelectedItem != null)
    {
        if (grid.SelectedItem != null)
        {
            grid.UpdateLayout();
            grid.ScrollIntoView(grid.SelectedItem, null);
        }
    }
}

private static void DataGrid_SelectionChanged(object sender, Microsoft.UI.Xaml.Controls.SelectionChangedEventArgs e)
{
    DataGrid grid = sender as DataGrid;
    if (grid != null && grid.IsLoaded)
    {
        var item = e.AddedItems.LastOrDefault();
        if (item != null)
        {
            grid.UpdateLayout();
            grid.ScrollIntoView(item, null);
        }
    }
}

public static void SetAutoScrollOnSelect(UIElement d, bool value)
{
    d.SetValue(AutoScrollOnSelectProperty, value);
}

public static bool GetAutoScrollOnSelect(UIElement obj)
{
    return (bool)obj.GetValue(AutoScrollOnSelectProperty);
}

}
3. In WinUI3 app, inside a page, use the property: xmlns:dgext="using:CGI.WinUI.Controls.Extensions" <dg:DataGrid ItemsSource="{Binding Path=Interruptions}"
AutoGenerateColumns="False"
Grid.Row="1" IsReadOnly="True"
SelectionMode="Single"
RowDetailsVisibilityMode="VisibleWhenSelected"
RowDetailsTemplate="{StaticResource PanneDataTemplate}"
dgext:DataGridExtension.AutoScrollOnSelect="True" <!- HERE!!!!!!!!!!!! -->
SelectedItem="{Binding Path=SelectedItem, Mode=TwoWay}">`

Expected behavior

Attached property to be found, and program to compile.

Screenshots

image

NuGet package version

WinUI 3 - Windows App SDK 1.4.3: 1.4.231115000

Windows version

Windows 10 (1809): Build 17763

Additional context

Interesting, the same attached property when moved into the main Application assembly works perfectly. It is really the fact that it's located inside another assembly that seems to be the problem.

No response

@Al-Caron Al-Caron added the bug Something isn't working label Dec 18, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Dec 18, 2023
@Al-Caron
Copy link
Author

Sorry, Closing... I found my problem!!!!!!

I'm terribly sorry. Error in character casing in the namespace. Don't know why it didn't show up. Working fine!

@microsoft-github-policy-service microsoft-github-policy-service bot added needs-triage Issue needs to be triaged by the area owners and removed needs-triage Issue needs to be triaged by the area owners labels Dec 19, 2023
@Al-Caron Al-Caron closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot removed the needs-triage Issue needs to be triaged by the area owners label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant