Click here to Skip to main content
15,898,752 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Floating progress visualization with button control Pin
Richard Deeming10-Aug-23 0:26
mveRichard Deeming10-Aug-23 0:26 
GeneralRe: Floating progress visualization with button control Pin
Evilfish200010-Aug-23 0:47
Evilfish200010-Aug-23 0:47 
AnswerRe: Floating progress visualization with button control Pin
Gerry Schmitz10-Aug-23 6:11
mveGerry Schmitz10-Aug-23 6:11 
QuestionWPF EF Core 6 DP Question Pin
Kevin Marois24-Jul-23 14:42
professionalKevin Marois24-Jul-23 14:42 
AnswerRe: WPF EF Core 6 DP Question Pin
Richard Deeming24-Jul-23 21:36
mveRichard Deeming24-Jul-23 21:36 
GeneralRe: WPF EF Core 6 DP Question Pin
Kevin Marois25-Jul-23 8:10
professionalKevin Marois25-Jul-23 8:10 
GeneralRe: WPF EF Core 6 DP Question Pin
Richard Deeming25-Jul-23 21:41
mveRichard Deeming25-Jul-23 21:41 
GeneralRe: WPF EF Core 6 DP Question Pin
Kevin Marois27-Jul-23 19:27
professionalKevin Marois27-Jul-23 19:27 
GeneralRe: WPF EF Core 6 DP Question Pin
Richard Deeming30-Jul-23 21:55
mveRichard Deeming30-Jul-23 21:55 
QuestionWPF xceed CheckcComboBox SelectAll Text Pin
Kevin Marois20-Jun-23 18:17
professionalKevin Marois20-Jun-23 18:17 
AnswerRe: WPF xceed CheckcComboBox SelectAll Text Pin
Richard Deeming20-Jun-23 20:53
mveRichard Deeming20-Jun-23 20:53 
GeneralRe: WPF xceed CheckcComboBox SelectAll Text Pin
Kevin Marois21-Jun-23 10:32
professionalKevin Marois21-Jun-23 10:32 
QuestionList of Images Pin
Kevin Marois9-Jun-23 13:47
professionalKevin Marois9-Jun-23 13:47 
QuestionChange Image URL's Assembly At Runtime Pin
Kevin Marois6-Jun-23 7:15
professionalKevin Marois6-Jun-23 7:15 
AnswerRe: Change Image URL's Assembly At Runtime Pin
Gerry Schmitz6-Jun-23 15:52
mveGerry Schmitz6-Jun-23 15:52 
Questionc# Spotify API not returning correctly. Pin
elfenliedtopfan52-Jun-23 18:03
elfenliedtopfan52-Jun-23 18:03 
AnswerRe: c# Spotify API not returning correctly. Pin
Pete O'Hanlon4-Jun-23 8:42
mvePete O'Hanlon4-Jun-23 8:42 
AnswerRe: c# Spotify API not returning correctly. Pin
jschell5-Jun-23 5:01
jschell5-Jun-23 5:01 
QuestionNeed help please regarding your awesome WPF MultiComboBox project :) Pin
Member 1160463425-May-23 5:21
Member 1160463425-May-23 5:21 
AnswerRe: Need help please regarding your awesome WPF MultiComboBox project :) Pin
jeron125-May-23 5:50
jeron125-May-23 5:50 
AnswerRe: Need help please regarding your awesome WPF MultiComboBox project :) Pin
Richard Deeming25-May-23 21:28
mveRichard Deeming25-May-23 21:28 
QuestionNavigationControl - Part 3 Pin
Kevin Marois14-May-23 8:01
professionalKevin Marois14-May-23 8:01 
AnswerRe: NavigationControl - Part 3 Pin
Richard Deeming14-May-23 21:40
mveRichard Deeming14-May-23 21:40 
GeneralRe: NavigationControl - Part 3 Pin
Kevin Marois15-May-23 17:14
professionalKevin Marois15-May-23 17:14 
Thanks, I understand the change you recommened, but it doesn't seem to change anything. I have two different issues. I beleive I solved the first one.
  1. The Projects pane should be expanded on startup BEFORE it loads so the user seees the wait indicator. This bit of code in the MainWindow simulates storing and resetting it from settings later on. if there was an ExpandedExpanded (past-tense) then I could call Load() from there.
Main Window.cs
NavigationPaneInfos = new List<NavigationPaneModel>
{
    new NavigationPaneModel
    {
        Header = "Projects", 
        NavigationItemType = NavigationItemType.Project, 
        DataSource = Functional.Apply(Repository.GetNavigationItems, NavigationItemType.Project),
        IsExpanded = true   // <====== 1. This should force the Projects pane to expand on startup, and that should trigger Load() after the wait indicator is visible
    },

    new NavigationPaneModel
    {
        Header = "Inventory", 
        NavigationItemType = NavigationItemType.Inventory,
        DataSource = Functional.Apply(Repository.GetNavigationItems, NavigationItemType.Inventory),
    },

    new NavigationPaneModel
    {
        Header = "Companies" , 
        NavigationItemType = NavigationItemType.Company,
        DataSource = Functional.Apply(Repository.GetNavigationItems, NavigationItemType.Company),
    },

    new NavigationPaneModel
    {
        Header = "Employees", 
        NavigationItemType = NavigationItemType.Employee,
        DataSource = Functional.Apply(Repository.GetNavigationItems, NavigationItemType.Employee),
    }
};
so, that caused this
private static object CoerceIsPaneExpanded(DependencyObject d, object baseValue)
{
    var control = (NavigationPane)d;
    var newVal = control._isInitialized ? baseValue : (object)false;
    return newVal; //<======= THIS IS NEVER TRUE
}
and
private void NavigationPane_Initialized(object? sender, EventArgs e)
{
    _isInitialized = true;
    CoerceValue(IsPaneExpandedProperty);

    if (_isPaneExpanded) //<====== 2. THIS IS NEVER TRUE
    {
        _ = Load();
    }
}
so, I added this, which correctly sets _isPaneExpanded based off the value set in the main window
private static async void OnNavigationPaneModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    var control = (NavigationPane)d;
    var model = e.NewValue as NavigationPaneModel;
    if (model != null)
    {
        control._isPaneExpanded = model.IsExpanded;
    }
}

This is where the UI is freezing up
private async Task Load()
{
    if (NavigationPaneModel != null && NavigationPaneModel.DataSource != null)
    {
        // 2. This calls the repo and returns data, but it's not async, which is 
        // causing the UI to frees
        var dataSource = NavigationPaneModel.DataSource(); 

        List<NavigationEntity>? data = null;

        if (dataSource != null)
        {
            data = await Task.Run(() => dataSource);
        }

        if (data != null)
        {
            Items = new ObservableCollection<NavigationEntity>(data);
        }
    }
}
so I tried this but....
private async Task Load()
{
    if (NavigationPaneModel != null && NavigationPaneModel.DataSource != null)
    {
        List<NavigationEntity>? data = null;

        await Task.Run(() => 
        {
            // This throws with
            //
            //  "The calling thread cannot access this object because a different thread owns it.'"
            //
            // So I need to figure out how to call the delegate async
            data = NavigationPaneModel.DataSource();
        });

        if (data != null)
        {
            Items = new ObservableCollection<NavigationEntity>(data);
        }
    }
}
So, it seems like all that's left is to get the backend call to fire async. The delegate was set in the UI using
NavigationPaneModel.DataSource = Functional.Apply(Repository.GetNavigationItems, NavigationItemType.Project)
How can I invoke the delegate async from Load()?

I checked my code into the repo.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

QuestionBubbling Event Question Pin
Kevin Marois9-May-23 14:32
professionalKevin Marois9-May-23 14:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.